diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b33f771b9c..3d98de7755 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1551,18 +1551,6 @@ parameters: count: 1 path: src/Type/Php/CompactFunctionReturnTypeExtension.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/DefineConstantTypeSpecifyingExtension.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/DefinedConstantTypeSpecifyingExtension.php - - rawMessage: 'Doing instanceof PHPStan\Type\TypeWithClassName is error-prone and deprecated. Use Type::getObjectClassNames() or Type::getObjectClassReflections() instead.' identifier: phpstanApi.instanceofType diff --git a/src/Type/Php/DefineConstantTypeSpecifyingExtension.php b/src/Type/Php/DefineConstantTypeSpecifyingExtension.php index 290f6fe437..711a334770 100644 --- a/src/Type/Php/DefineConstantTypeSpecifyingExtension.php +++ b/src/Type/Php/DefineConstantTypeSpecifyingExtension.php @@ -11,7 +11,6 @@ use PHPStan\Analyser\TypeSpecifierContext; use PHPStan\DependencyInjection\AutowiredService; use PHPStan\Reflection\FunctionReflection; -use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\FunctionTypeSpecifyingExtension; use function count; @@ -45,23 +44,21 @@ public function specifyTypes( ): SpecifiedTypes { $args = $node->getArgs(); - $constantName = $scope->getType($args[0]->value); - if ( - !$constantName instanceof ConstantStringType - || $constantName->getValue() === '' - ) { + $constantNames = $scope->getType($args[0]->value)->getConstantStrings(); + + if (count($constantNames) !== 1 || $constantNames[0]->getValue() === '') { return new SpecifiedTypes([], []); } $valueType = $scope->getType($args[1]->value); $finalType = $scope->getConstantExplicitTypeFromConfig( - $constantName->getValue(), + $constantNames[0]->getValue(), $valueType, ); return $this->typeSpecifier->create( new Node\Expr\ConstFetch( - new Node\Name\FullyQualified($constantName->getValue()), + new Node\Name\FullyQualified($constantNames[0]->getValue()), ), $finalType, TypeSpecifierContext::createTruthy(), diff --git a/src/Type/Php/DefinedConstantTypeSpecifyingExtension.php b/src/Type/Php/DefinedConstantTypeSpecifyingExtension.php index df0fe21f2b..e371fbbcdb 100644 --- a/src/Type/Php/DefinedConstantTypeSpecifyingExtension.php +++ b/src/Type/Php/DefinedConstantTypeSpecifyingExtension.php @@ -10,7 +10,6 @@ use PHPStan\Analyser\TypeSpecifierContext; use PHPStan\DependencyInjection\AutowiredService; use PHPStan\Reflection\FunctionReflection; -use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\FunctionTypeSpecifyingExtension; use PHPStan\Type\MixedType; use function count; @@ -48,15 +47,14 @@ public function specifyTypes( TypeSpecifierContext $context, ): SpecifiedTypes { - $constantName = $scope->getType($node->getArgs()[0]->value); - if ( - !$constantName instanceof ConstantStringType - || $constantName->getValue() === '' - ) { + $args = $node->getArgs(); + $constantNames = $scope->getType($args[0]->value)->getConstantStrings(); + + if (count($constantNames) !== 1 || $constantNames[0]->getValue() === '') { return new SpecifiedTypes([], []); } - $expr = $this->constantHelper->createExprFromConstantName($constantName->getValue()); + $expr = $this->constantHelper->createExprFromConstantName($constantNames[0]->getValue()); if ($expr === null) { return new SpecifiedTypes([], []); }