diff --git a/build/target-repository/composer.json b/build/target-repository/composer.json index 0941b42824e..567a157c717 100644 --- a/build/target-repository/composer.json +++ b/build/target-repository/composer.json @@ -9,7 +9,7 @@ ], "require": { "php": "^7.4|^8.0", - "phpstan/phpstan": "^2.1.33" + "phpstan/phpstan": "^2.1.34" }, "autoload": { "files": [ diff --git a/composer.json b/composer.json index ca62ce933b1..0685b56efa7 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "nikic/php-parser": "^5.7", "ondram/ci-detector": "^4.2", "phpstan/phpdoc-parser": "^2.3", - "phpstan/phpstan": "^2.1.33", + "phpstan/phpstan": "^2.1.34", "react/event-loop": "^1.6", "react/promise": "^3.3", "react/socket": "^1.17", diff --git a/phpstan.neon b/phpstan.neon index b683b853111..006290f3913 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -438,3 +438,29 @@ parameters: - identifier: symplify.noMissnamedDocTag path: rules/TypeDeclarationDocblocks/TypeResolver/ConstantArrayTypeGeneralizer.php + + - + identifier: typePerfect.narrowReturnObjectType + path: src/PHPStan/ScopeFetcher.php + + - + identifier: varTag.nativeType + path: src/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php + + - + identifier: argument.type + paths: + - rules/Privatization/TypeManipulator/TypeNormalizer.php + - rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php + - rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php + - rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php + - rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php + - rules/TypeDeclarationDocblocks/Rector/Class_/AddVarArrayDocblockFromDimFetchAssignRector.php + - src/NodeTypeResolver/PHPStan/Type/TypeFactory.php + + - + identifier: argument.templateType + paths: + - rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php + - rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php + - src/NodeTypeResolver/PHPStan/Type/TypeFactory.php diff --git a/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php b/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php index fcdd417d65f..28ed5a20ec0 100644 --- a/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php +++ b/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php @@ -4,6 +4,7 @@ namespace Rector\Php81\NodeManipulator; +use PHPStan\Analyser\Fiber\FiberScope; use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Cast\Int_ as CastInt_; @@ -213,6 +214,10 @@ private function isAnErrorType(Expr $expr, Type $type, Scope $scope): bool } $parentScope = $scope->getParentScope(); + if ($parentScope instanceof FiberScope) { + $parentScope = $parentScope->toMutatingScope(); + } + if ($parentScope instanceof Scope) { return $parentScope->getType($expr) instanceof ErrorType; } diff --git a/src/DependencyInjection/PHPStan/PHPStanContainerMemento.php b/src/DependencyInjection/PHPStan/PHPStanContainerMemento.php index f130414c097..387750afaa7 100644 --- a/src/DependencyInjection/PHPStan/PHPStanContainerMemento.php +++ b/src/DependencyInjection/PHPStan/PHPStanContainerMemento.php @@ -9,8 +9,6 @@ use PHPStan\Parser\AnonymousClassVisitor; use PHPStan\Parser\ArrayMapArgVisitor; use PHPStan\Parser\RichParser; -use PHPStan\Parser\VariadicFunctionsVisitor; -use PHPStan\Parser\VariadicMethodsVisitor; use Rector\Util\Reflection\PrivatesAccessor; /** @@ -41,8 +39,6 @@ public static function removeRichVisitors(RichParser $richParser): void // remove all the rest, https://github.com/phpstan/phpstan-src/tree/1d86de8bb9371534983a8dbcd879e057d2ff028f/src/Parser $nodeVisitorsToKeep = [ $container->findServiceNamesByType(AnonymousClassVisitor::class)[0] => true, - $container->findServiceNamesByType(VariadicFunctionsVisitor::class)[0] => true, - $container->findServiceNamesByType(VariadicMethodsVisitor::class)[0] => true, $container->findServiceNamesByType(ArrayMapArgVisitor::class)[0] => true, ]; diff --git a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php index 0a36d5f8607..0db5d6a0bb8 100644 --- a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php +++ b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php @@ -4,6 +4,7 @@ namespace Rector\NodeTypeResolver\PHPStan\Scope; +use PHPStan\Analyser\Fiber\FiberScope; use Error; use PhpParser\Node; use PhpParser\Node\Arg; @@ -158,6 +159,10 @@ public function processNodes( &$nodeCallback, $filePath, ): void { + if ($mutatingScope instanceof FiberScope) { + $mutatingScope = $mutatingScope->toMutatingScope(); + } + // the class reflection is resolved AFTER entering to class node // so we need to get it from the first after this one if ($node instanceof Class_ || $node instanceof Interface_ || $node instanceof Enum_) { diff --git a/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php b/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php index d1e6a4b135b..f5fc2e9dd12 100644 --- a/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php +++ b/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php @@ -6,9 +6,8 @@ use PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator; use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator; -use PHPStan\Reflection\BetterReflection\SourceLocator\FileNodesFetcher; use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorFactory; -use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocator; +use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorRepository; use Rector\Contract\DependencyInjection\ResettableInterface; use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment; @@ -30,8 +29,8 @@ final class DynamicSourceLocatorProvider implements ResettableInterface private ?AggregateSourceLocator $aggregateSourceLocator = null; public function __construct( - private readonly FileNodesFetcher $fileNodesFetcher, - private readonly OptimizedDirectorySourceLocatorFactory $optimizedDirectorySourceLocatorFactory + private readonly OptimizedDirectorySourceLocatorFactory $optimizedDirectorySourceLocatorFactory, + private readonly OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository ) { } @@ -68,7 +67,7 @@ public function provide(): SourceLocator $sourceLocators = []; foreach ($this->filePaths as $file) { - $sourceLocators[] = new OptimizedSingleFileSourceLocator($this->fileNodesFetcher, $file); + $sourceLocators[] = $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($file); } foreach ($this->directories as $directory) {