Skip to content

Commit

Permalink
[NodeManipulator] Reduce parent lookup on PropertyFetchAssignManipula…
Browse files Browse the repository at this point in the history
…tor (#4036)
  • Loading branch information
samsonasik committed May 31, 2023
1 parent 227186b commit 98fa6b5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/NodeManipulator/PropertyFetchAssignManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Property;
use PhpParser\NodeTraverser;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
Expand Down Expand Up @@ -43,17 +45,17 @@ public function isAssignedMultipleTimesInConstructor(Property $property): bool

$this->simpleCallableNodeTraverser->traverseNodesWithCallable(
(array) $classMethod->getStmts(),
function (Node $node) use ($propertyName, $classLike, &$count): ?int {
if (! $node instanceof Assign) {
return null;
function (Node $node) use ($propertyName, &$count): ?int {
// skip anonymous classes and inner function
if ($node instanceof Class_ || $node instanceof Function_) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}

if (! $this->propertyFetchAnalyzer->isLocalPropertyFetchName($node->var, $propertyName)) {
if (! $node instanceof Assign) {
return null;
}

$parentClassLike = $this->betterNodeFinder->findParentType($node, ClassLike::class);
if ($parentClassLike !== $classLike) {
if (! $this->propertyFetchAnalyzer->isLocalPropertyFetchName($node->var, $propertyName)) {
return null;
}

Expand Down

0 comments on commit 98fa6b5

Please sign in to comment.