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; }