diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6889444c32..9e76470a1b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1599,12 +1599,6 @@ parameters: count: 1 path: src/Type/Php/NumberFormatFunctionDynamicReturnTypeExtension.php - - - rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.' - identifier: phpstanApi.instanceofType - count: 1 - path: src/Type/Php/NumberFormatFunctionDynamicReturnTypeExtension.php - - rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.' identifier: phpstanApi.instanceofType @@ -1623,18 +1617,6 @@ parameters: count: 1 path: src/Type/Php/ReflectionMethodConstructorThrowTypeExtension.php - - - rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.' - identifier: phpstanApi.instanceofType - count: 1 - path: src/Type/Php/SscanfFunctionDynamicReturnTypeExtension.php - - - - rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.' - identifier: phpstanApi.instanceofType - count: 1 - path: src/Type/Php/StrRepeatFunctionReturnTypeExtension.php - - rawMessage: 'Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.' identifier: phpstanApi.instanceofType diff --git a/src/Type/Php/NumberFormatFunctionDynamicReturnTypeExtension.php b/src/Type/Php/NumberFormatFunctionDynamicReturnTypeExtension.php index 8da8eda986..d3024c2160 100644 --- a/src/Type/Php/NumberFormatFunctionDynamicReturnTypeExtension.php +++ b/src/Type/Php/NumberFormatFunctionDynamicReturnTypeExtension.php @@ -7,12 +7,12 @@ use PHPStan\DependencyInjection\AutowiredService; use PHPStan\Reflection\FunctionReflection; use PHPStan\Type\Accessory\AccessoryNumericStringType; -use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\ConstantScalarType; use PHPStan\Type\DynamicFunctionReturnTypeExtension; use PHPStan\Type\IntersectionType; use PHPStan\Type\StringType; use PHPStan\Type\Type; +use function count; use function in_array; #[AutowiredService] @@ -34,7 +34,8 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $thousandsType = $scope->getType($functionCall->getArgs()[3]->value); $decimalType = $scope->getType($functionCall->getArgs()[2]->value); - if (!$thousandsType instanceof ConstantStringType || $thousandsType->getValue() !== '') { + $constantThousandsTypes = $thousandsType->getConstantStrings(); + if (count($constantThousandsTypes) !== 1 || $constantThousandsTypes[0]->getValue() !== '') { return $stringType; } diff --git a/src/Type/Php/SscanfFunctionDynamicReturnTypeExtension.php b/src/Type/Php/SscanfFunctionDynamicReturnTypeExtension.php index de22ba0a46..ab48c2f31b 100644 --- a/src/Type/Php/SscanfFunctionDynamicReturnTypeExtension.php +++ b/src/Type/Php/SscanfFunctionDynamicReturnTypeExtension.php @@ -10,7 +10,6 @@ use PHPStan\Type\Accessory\AccessoryNonFalsyStringType; use PHPStan\Type\Constant\ConstantArrayTypeBuilder; use PHPStan\Type\Constant\ConstantIntegerType; -use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\DynamicFunctionReturnTypeExtension; use PHPStan\Type\FloatType; use PHPStan\Type\IntegerType; @@ -42,11 +41,11 @@ public function getTypeFromFunctionCall( return null; } - $formatType = $scope->getType($args[1]->value); - - if (!$formatType instanceof ConstantStringType) { + $formatType = $scope->getType($args[1]->value)->getConstantStrings(); + if (count($formatType) !== 1) { return null; } + $formatType = $formatType[0]; if (preg_match_all('/%(\d*)(\[[^\]]+\]|[cdeEfosux]{1})/', $formatType->getValue(), $matches) > 0) { $arrayBuilder = ConstantArrayTypeBuilder::createEmpty(); diff --git a/src/Type/Php/StrRepeatFunctionReturnTypeExtension.php b/src/Type/Php/StrRepeatFunctionReturnTypeExtension.php index 585c02bf9b..ba8e6a0d23 100644 --- a/src/Type/Php/StrRepeatFunctionReturnTypeExtension.php +++ b/src/Type/Php/StrRepeatFunctionReturnTypeExtension.php @@ -56,13 +56,15 @@ public function getTypeFromFunctionCall( } $inputType = $scope->getType($args[0]->value); - if ( - $inputType instanceof ConstantStringType - && $multiplierType instanceof ConstantIntegerType - // don't generate type too big to avoid hitting memory limit - && strlen($inputType->getValue()) * $multiplierType->getValue() < 100 - ) { - return new ConstantStringType(str_repeat($inputType->getValue(), $multiplierType->getValue())); + if ($multiplierType instanceof ConstantIntegerType) { + $constantInputStrings = $inputType->getConstantStrings(); + if ( + count($constantInputStrings) === 1 + // don't generate type too big to avoid hitting memory limit + && strlen($constantInputStrings[0]->getValue()) * $multiplierType->getValue() < 100 + ) { + return new ConstantStringType(str_repeat($constantInputStrings[0]->getValue(), $multiplierType->getValue())); + } } $accessoryTypes = [];