Skip to content

Commit

Permalink
[NodeManipulator] Reduce parent lookup on PropertyManipulator under U…
Browse files Browse the repository at this point in the history
…nset_ (#4273)
  • Loading branch information
samsonasik committed Jun 18, 2023
1 parent 805b7b7 commit 3806bb8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/NodeTypeResolver/Node/AttributeKey.php
Expand Up @@ -226,4 +226,9 @@ final class AttributeKey
* @var string
*/
public const IS_IN_LOOP = 'is_in_loop';

/**
* @var string
*/
public const IS_UNSET_VAR = 'is_unset_var';
}
Expand Up @@ -13,6 +13,7 @@
use PhpParser\Node\Stmt\For_;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Unset_;
use PhpParser\Node\Stmt\While_;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
Expand Down Expand Up @@ -46,6 +47,12 @@ static function (Node $subNode): ?int {
return null;
}

if ($node instanceof Unset_) {
foreach ($node->vars as $var) {
$var->setAttribute(AttributeKey::IS_UNSET_VAR, true);
}
}

return null;
}
}
3 changes: 1 addition & 2 deletions src/NodeManipulator/PropertyManipulator.php
Expand Up @@ -108,8 +108,7 @@ public function isPropertyChangeableExceptConstructor(
return true;
}

$isInUnset = (bool) $this->betterNodeFinder->findParentType($propertyFetch, Unset_::class);
if ($isInUnset) {
if ($propertyFetch->getAttribute(AttributeKey::IS_UNSET_VAR) === true) {
return true;
}
}
Expand Down

0 comments on commit 3806bb8

Please sign in to comment.