Skip to content

Commit

Permalink
Updated Rector to commit 8aaee5ec80df459fe507746817aef442a05916ae
Browse files Browse the repository at this point in the history
rectorphp/rector-src@8aaee5e [Performance] Cache should traverse for AddUseStatementGuard (#6234)
  • Loading branch information
TomasVotruba committed Aug 22, 2024
1 parent dc2d69a commit aa33f42
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '4f89b7498e7bfb7dccc8872e042fcbc3a687a7f1';
public const PACKAGE_VERSION = '8aaee5ec80df459fe507746817aef442a05916ae';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-08-22 10:53:33';
public const RELEASE_DATE = '2024-08-22 10:57:41';
/**
* @var int
*/
Expand Down
4 changes: 3 additions & 1 deletion src/PostRector/Application/PostFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ public function reset() : void
public function traverse(array $stmts, File $file) : array
{
foreach ($this->getPostRectors() as $postRector) {
// file must be set early into PostRector class to ensure its usage
// always match on skipping process
$postRector->setFile($file);
if ($this->shouldSkipPostRector($postRector, $file->getFilePath(), $stmts)) {
continue;
}
$postRector->setFile($file);
$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor($postRector);
$stmts = $nodeTraverser->traverse($stmts);
Expand Down
13 changes: 10 additions & 3 deletions src/PostRector/Guard/AddUseStatementGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ class AddUseStatementGuard
* @var \Rector\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
/**
* @var array<string, bool>
*/
private $shouldTraverseOnFiles = [];
public function __construct(BetterNodeFinder $betterNodeFinder)
{
$this->betterNodeFinder = $betterNodeFinder;
}
/**
* @param Stmt[] $stmts
*/
public function shouldTraverse(array $stmts) : bool
public function shouldTraverse(array $stmts, string $filePath) : bool
{
if (isset($this->shouldTraverseOnFiles[$filePath])) {
return $this->shouldTraverseOnFiles[$filePath];
}
$totalNamespaces = 0;
// just loop the first level stmts to locate namespace to improve performance
// as namespace is always on first level
Expand All @@ -32,9 +39,9 @@ public function shouldTraverse(array $stmts) : bool
}
// skip if 2 namespaces are present
if ($totalNamespaces === 2) {
return \false;
return $this->shouldTraverseOnFiles[$filePath] = \false;
}
}
return !$this->betterNodeFinder->hasInstancesOf($stmts, [InlineHTML::class]);
return $this->shouldTraverseOnFiles[$filePath] = !$this->betterNodeFinder->hasInstancesOf($stmts, [InlineHTML::class]);
}
}
2 changes: 1 addition & 1 deletion src/PostRector/Rector/DocblockNameImportingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public function enterNode(Node $node)
*/
public function shouldTraverse(array $stmts) : bool
{
return $this->addUseStatementGuard->shouldTraverse($stmts);
return $this->addUseStatementGuard->shouldTraverse($stmts, $this->getFile()->getFilePath());
}
}
2 changes: 1 addition & 1 deletion src/PostRector/Rector/NameImportingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function enterNode(Node $node)
*/
public function shouldTraverse(array $stmts) : bool
{
return $this->addUseStatementGuard->shouldTraverse($stmts);
return $this->addUseStatementGuard->shouldTraverse($stmts, $this->getFile()->getFilePath());
}
/**
* @param array<Use_|GroupUse> $currentUses
Expand Down

0 comments on commit aa33f42

Please sign in to comment.