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
14 changes: 0 additions & 14 deletions build/baseline-7.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,6 @@ parameters:
count: 1
path: ../src/Reflection/BetterReflection/SourceLocator/CachingVisitor.php

-
message: "#^Class PHPStan\\\\Reflection\\\\BetterReflection\\\\SourceLocator\\\\CachingVisitor has an uninitialized property \\$classNodes\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: ../src/Reflection/BetterReflection/SourceLocator/CachingVisitor.php

-
message: "#^Class PHPStan\\\\Reflection\\\\BetterReflection\\\\SourceLocator\\\\CachingVisitor has an uninitialized property \\$functionNodes\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: ../src/Reflection/BetterReflection/SourceLocator/CachingVisitor.php

-
message: "#^Class PHPStan\\\\Reflection\\\\BetterReflection\\\\SourceLocator\\\\CachingVisitor has an uninitialized property \\$constantNodes\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: ../src/Reflection/BetterReflection/SourceLocator/CachingVisitor.php
-
message: "#^Class PHPStan\\\\Reflection\\\\ReflectionProvider\\\\SetterReflectionProviderProvider has an uninitialized property \\$reflectionProvider\\. Give it default value or assign it in the constructor\\.$#"
count: 1
Expand Down
1 change: 1 addition & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ services:
class: PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorFactory
arguments:
fileFinder: @fileFinderScan
phpParser: @currentPhpVersionPhpParser

-
class: PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorRepository
Expand Down
16 changes: 10 additions & 6 deletions src/Reflection/BetterReflection/SourceLocator/CachingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class CachingVisitor extends NodeVisitorAbstract
private string $contents;

/** @var array<string, array<FetchedNode<Node\Stmt\ClassLike>>> */
private array $classNodes;
private array $classNodes = [];

/** @var array<string, array<FetchedNode<Node\Stmt\Function_>>> */
private array $functionNodes;
private array $functionNodes = [];

/** @var array<string, array<FetchedNode<Node\Stmt\Const_|Node\Expr\FuncCall>>> */
private array $constantNodes;
private array $constantNodes = [];

private ?Node\Stmt\Namespace_ $currentNamespaceNode = null;

Expand Down Expand Up @@ -146,13 +146,17 @@ public function getConstantNodes(): array
return $this->constantNodes;
}

public function reset(string $fileName, string $contents): void
public function prepare(string $fileName, string $contents): void
{
$this->fileName = $fileName;
$this->contents = $contents;
}

public function reset(): void
{
$this->classNodes = [];
$this->functionNodes = [];
$this->constantNodes = [];
$this->fileName = $fileName;
$this->contents = $contents;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
class FileNodesFetcher
{

private NodeTraverser $nodeTraverser;

public function __construct(
private CachingVisitor $cachingVisitor,
private Parser $parser,
)
{
$this->nodeTraverser = new NodeTraverser();
$this->nodeTraverser->addVisitor($this->cachingVisitor);
}

public function fetchNodes(string $fileName): FetchedNodesResult
{
$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor($this->cachingVisitor);

$contents = FileReader::read($fileName);

try {
Expand All @@ -31,16 +32,17 @@ public function fetchNodes(string $fileName): FetchedNodesResult
} catch (ParserErrorsException) {
return new FetchedNodesResult([], [], []);
}
$this->cachingVisitor->reset($fileName, $contents);
$nodeTraverser->traverse($ast);

$this->cachingVisitor->prepare($fileName, $contents);
$this->nodeTraverser->traverse($ast);

$result = new FetchedNodesResult(
$this->cachingVisitor->getClassNodes(),
$this->cachingVisitor->getFunctionNodes(),
$this->cachingVisitor->getConstantNodes(),
);

$this->cachingVisitor->reset($fileName, $contents);
$this->cachingVisitor->reset();

return $result;
}
Expand Down
Loading