Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/Reflection/BetterReflection/SourceLocator/CachingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -23,7 +26,7 @@ final class CachingVisitor extends NodeVisitorAbstract

private string $contents;

/** @var array<string, list<FetchedNode<Node\Stmt\ClassLike>>> */
/** @var array<string, list<FetchedNode<ClassLikeNode>>> */
private array $classNodes;

/** @var array<string, list<FetchedNode<Node\Stmt\Function_>>> */
Expand All @@ -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) {
Expand Down Expand Up @@ -127,7 +135,7 @@ public function leaveNode(Node $node)
}

/**
* @return array<string, list<FetchedNode<Node\Stmt\ClassLike>>>
* @return array<string, list<FetchedNode<ClassLikeNode>>>
*/
public function getClassNodes(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, list<FetchedNode<Node\Stmt\ClassLike>>> $classNodes
* @param array<string, list<FetchedNode<ClassLikeNode>>> $classNodes
* @param array<string, list<FetchedNode<Node\Stmt\Function_>>> $functionNodes
* @param array<string, list<FetchedNode<Node\Stmt\Const_|Node\Expr\FuncCall>>> $constantNodes
*/
Expand All @@ -21,7 +24,7 @@ public function __construct(
}

/**
* @return array<string, list<FetchedNode<Node\Stmt\ClassLike>>>
* @return array<string, list<FetchedNode<ClassLikeNode>>>
*/
public function getClassNodes(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
use function sprintf;
use function strtolower;

/**
* @phpstan-import-type ClassLikeNode from FetchedNodesResult
*/
final class OptimizedDirectorySourceLocator implements SourceLocator
{

Expand Down Expand Up @@ -141,7 +144,7 @@ public function locateIdentifier(Reflector $reflector, Identifier $identifier):
return null;
}

/** @var FetchedNode<Node\Stmt\ClassLike> $fetchedClassNode */
/** @var FetchedNode<ClassLikeNode> $fetchedClassNode */
$fetchedClassNode = current($fetchedClassNodes[$identifierName]);
$fetchedFile = $file;
}
Expand Down Expand Up @@ -205,7 +208,7 @@ public function locateIdentifier(Reflector $reflector, Identifier $identifier):
}

/**
* @param FetchedNode<Node\Stmt\ClassLike>|FetchedNode<Node\Stmt\Function_>|FetchedNode<Node\Stmt\Const_|Node\Expr\FuncCall> $fetchedNode
* @param FetchedNode<ClassLikeNode>|FetchedNode<Node\Stmt\Function_>|FetchedNode<Node\Stmt\Const_|Node\Expr\FuncCall> $fetchedNode
*/
private function nodeToReflection(Reflector $reflector, FetchedNode $fetchedNode, ?int $positionInNode = null): ReflectionClass|ReflectionConstant|ReflectionFunction
{
Expand Down
Loading