diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fef664d8b3..da665d4dca 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -360,30 +360,12 @@ parameters: count: 1 path: src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php - - - rawMessage: 'Parameter #2 $node of method PHPStan\BetterReflection\SourceLocator\Ast\Strategy\NodeToReflection::__invoke() expects PhpParser\Node\Expr\ArrowFunction|PhpParser\Node\Expr\Closure|PhpParser\Node\Expr\FuncCall|PhpParser\Node\Stmt\Class_|PhpParser\Node\Stmt\Const_|PhpParser\Node\Stmt\Enum_|PhpParser\Node\Stmt\Function_|PhpParser\Node\Stmt\Interface_|PhpParser\Node\Stmt\Trait_, PhpParser\Node\Stmt\ClassLike given.' - identifier: argument.type - count: 1 - path: src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php - - rawMessage: 'Method PHPStan\Reflection\BetterReflection\SourceLocator\FileReadTrapStreamWrapper::invokeWithRealFileStreamWrapper() has parameter $cb with no signature specified for callable.' identifier: missingType.callable count: 1 path: src/Reflection/BetterReflection/SourceLocator/FileReadTrapStreamWrapper.php - - - rawMessage: 'Parameter #2 $node of method PHPStan\BetterReflection\SourceLocator\Ast\Strategy\NodeToReflection::__invoke() expects PhpParser\Node\Expr\ArrowFunction|PhpParser\Node\Expr\Closure|PhpParser\Node\Expr\FuncCall|PhpParser\Node\Stmt\Class_|PhpParser\Node\Stmt\Const_|PhpParser\Node\Stmt\Enum_|PhpParser\Node\Stmt\Function_|PhpParser\Node\Stmt\Interface_|PhpParser\Node\Stmt\Trait_, PhpParser\Node\Expr\FuncCall|PhpParser\Node\Stmt\ClassLike|PhpParser\Node\Stmt\Const_|PhpParser\Node\Stmt\Function_ given.' - identifier: argument.type - count: 1 - path: src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php - - - - rawMessage: 'Parameter #2 $node of method PHPStan\BetterReflection\SourceLocator\Ast\Strategy\NodeToReflection::__invoke() expects PhpParser\Node\Expr\ArrowFunction|PhpParser\Node\Expr\Closure|PhpParser\Node\Expr\FuncCall|PhpParser\Node\Stmt\Class_|PhpParser\Node\Stmt\Const_|PhpParser\Node\Stmt\Enum_|PhpParser\Node\Stmt\Function_|PhpParser\Node\Stmt\Interface_|PhpParser\Node\Stmt\Trait_, PhpParser\Node\Stmt\ClassLike given.' - identifier: argument.type - count: 2 - path: src/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocator.php - - rawMessage: Creating new ReflectionClass is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine. Use objects retrieved from ReflectionProvider instead. identifier: phpstanApi.runtimeReflection diff --git a/src/Reflection/BetterReflection/SourceLocator/CachingVisitor.php b/src/Reflection/BetterReflection/SourceLocator/CachingVisitor.php index 25ed6bbe7d..70b6bb71bb 100644 --- a/src/Reflection/BetterReflection/SourceLocator/CachingVisitor.php +++ b/src/Reflection/BetterReflection/SourceLocator/CachingVisitor.php @@ -15,6 +15,9 @@ use function strtolower; // autoTag: false - must not be tagged as a RichParser node visitor +/** + * @phpstan-import-type ClassLikeNode from FetchedNodesResult + */ #[AutowiredService(autoTag: false)] final class CachingVisitor extends NodeVisitorAbstract { @@ -23,7 +26,7 @@ final class CachingVisitor extends NodeVisitorAbstract private string $contents; - /** @var array>> */ + /** @var array>> */ private array $classNodes; /** @var array>> */ @@ -43,7 +46,12 @@ public function enterNode(Node $node): ?int return null; } - if ($node instanceof Node\Stmt\ClassLike) { + if ( + $node instanceof Node\Stmt\Class_ + || $node instanceof Node\Stmt\Interface_ + || $node instanceof Node\Stmt\Trait_ + || $node instanceof Node\Stmt\Enum_ + ) { if ($node->name !== null) { $fullClassName = $node->name->toString(); if ($this->currentNamespaceNode !== null && $this->currentNamespaceNode->name !== null) { @@ -127,7 +135,7 @@ public function leaveNode(Node $node) } /** - * @return array>> + * @return array>> */ public function getClassNodes(): array { diff --git a/src/Reflection/BetterReflection/SourceLocator/FetchedNodesResult.php b/src/Reflection/BetterReflection/SourceLocator/FetchedNodesResult.php index 9061e3845a..a880d4e15f 100644 --- a/src/Reflection/BetterReflection/SourceLocator/FetchedNodesResult.php +++ b/src/Reflection/BetterReflection/SourceLocator/FetchedNodesResult.php @@ -4,11 +4,14 @@ use PhpParser\Node; +/** + * @phpstan-type ClassLikeNode = Node\Stmt\Class_|Node\Stmt\Interface_|Node\Stmt\Trait_|Node\Stmt\Enum_ + */ final class FetchedNodesResult { /** - * @param array>> $classNodes + * @param array>> $classNodes * @param array>> $functionNodes * @param array>> $constantNodes */ @@ -21,7 +24,7 @@ public function __construct( } /** - * @return array>> + * @return array>> */ public function getClassNodes(): array { diff --git a/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php b/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php index b83b5a35a1..54f75ba70c 100644 --- a/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php +++ b/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php @@ -30,6 +30,9 @@ use function sprintf; use function strtolower; +/** + * @phpstan-import-type ClassLikeNode from FetchedNodesResult + */ final class OptimizedDirectorySourceLocator implements SourceLocator { @@ -141,7 +144,7 @@ public function locateIdentifier(Reflector $reflector, Identifier $identifier): return null; } - /** @var FetchedNode $fetchedClassNode */ + /** @var FetchedNode $fetchedClassNode */ $fetchedClassNode = current($fetchedClassNodes[$identifierName]); $fetchedFile = $file; } @@ -205,7 +208,7 @@ public function locateIdentifier(Reflector $reflector, Identifier $identifier): } /** - * @param FetchedNode|FetchedNode|FetchedNode $fetchedNode + * @param FetchedNode|FetchedNode|FetchedNode $fetchedNode */ private function nodeToReflection(Reflector $reflector, FetchedNode $fetchedNode, ?int $positionInNode = null): ReflectionClass|ReflectionConstant|ReflectionFunction {