From 10e3e5c1180b6a30daafe790e49e648d2fb1467e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 2 Dec 2025 17:11:46 +0700 Subject: [PATCH] [Transform] Use ContextAnalyzer->isLeftPartOfAssign() on ArrayDimFetchToMethodCallRector --- .../ArrayDimFetchToMethodCallRector.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php b/rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php index cd333f5c9ea..0e3136ceb27 100644 --- a/rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php +++ b/rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php @@ -18,7 +18,7 @@ use PhpParser\NodeVisitor; use PHPStan\Type\ObjectType; use Rector\Contract\Rector\ConfigurableRectorInterface; -use Rector\NodeTypeResolver\Node\AttributeKey; +use Rector\NodeNestingScope\ContextAnalyzer; use Rector\Rector\AbstractRector; use Rector\Transform\ValueObject\ArrayDimFetchToMethodCall; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; @@ -35,6 +35,11 @@ final class ArrayDimFetchToMethodCallRector extends AbstractRector implements Co */ private array $arrayDimFetchToMethodCalls; + public function __construct( + private readonly ContextAnalyzer $contextAnalyzer + ) { + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change array dim fetch to method call', [ @@ -86,11 +91,7 @@ public function refactor(Node $node): array|Expr|null|int } // is part of assign, skip - if ($node->getAttribute(AttributeKey::IS_BEING_ASSIGNED)) { - return null; - } - - if ($node->getAttribute(AttributeKey::IS_ASSIGN_OP_VAR)) { + if ($this->contextAnalyzer->isLeftPartOfAssign($node)) { return null; }