Skip to content

Commit

Permalink
Updated Rector to commit 246de2dd9f7ce39e4ff94de0d36307e4fc8067b5
Browse files Browse the repository at this point in the history
rectorphp/rector-src@246de2d [Performance] Remove unnecessary usage of SimpleCallableNodeTraverser on UseImportsTraverser (#6288)
  • Loading branch information
TomasVotruba committed Sep 5, 2024
1 parent 9fd26b5 commit 93c6ecf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
35 changes: 14 additions & 21 deletions rules/CodingStyle/ClassNameImport/UseImportsTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,22 @@
declare (strict_types=1);
namespace Rector\CodingStyle\ClassNameImport;

use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use PhpParser\NodeTraverser;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
final class UseImportsTraverser
{
/**
* @readonly
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
*/
private $simpleCallableNodeTraverser;
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver)
public function __construct(NodeNameResolver $nodeNameResolver)
{
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
$this->nodeNameResolver = $nodeNameResolver;
}
/**
Expand All @@ -36,24 +27,26 @@ public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTrave
*/
public function traverserStmts(array $stmts, callable $callable) : void
{
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($stmts, function (Node $node) use($callable) : ?int {
if ($node instanceof Namespace_ || $node instanceof FileWithoutNamespace) {
// traverse into namespaces
return null;
foreach ($stmts as $stmt) {
if ($stmt instanceof Namespace_ || $stmt instanceof FileWithoutNamespace) {
$this->traverserStmts($stmt->stmts, $callable);
return;
}
if ($node instanceof Use_) {
foreach ($node->uses as $useUse) {
if (!$stmt instanceof Use_ && !$stmt instanceof GroupUse) {
continue;
}
if ($stmt instanceof Use_) {
foreach ($stmt->uses as $useUse) {
$name = $this->nodeNameResolver->getName($useUse);
if ($name === null) {
continue;
}
$callable($node->type, $useUse, $name);
$callable($stmt->type, $useUse, $name);
}
} elseif ($node instanceof GroupUse) {
$this->processGroupUse($node, $callable);
continue;
}
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
});
$this->processGroupUse($stmt, $callable);
}
}
/**
* @param callable(Use_::TYPE_* $useType, UseUse $useUse, string $name): void $callable
Expand Down
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 = '1c20d81c56a0ec9cb7663421add2bd1004278370';
public const PACKAGE_VERSION = '246de2dd9f7ce39e4ff94de0d36307e4fc8067b5';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-09-06 04:13:29';
public const RELEASE_DATE = '2024-09-06 04:17:37';
/**
* @var int
*/
Expand Down

0 comments on commit 93c6ecf

Please sign in to comment.