Skip to content

Commit 10e3e5c

Browse files
committed
[Transform] Use ContextAnalyzer->isLeftPartOfAssign() on ArrayDimFetchToMethodCallRector
1 parent 82f5181 commit 10e3e5c

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use PhpParser\NodeVisitor;
1919
use PHPStan\Type\ObjectType;
2020
use Rector\Contract\Rector\ConfigurableRectorInterface;
21-
use Rector\NodeTypeResolver\Node\AttributeKey;
21+
use Rector\NodeNestingScope\ContextAnalyzer;
2222
use Rector\Rector\AbstractRector;
2323
use Rector\Transform\ValueObject\ArrayDimFetchToMethodCall;
2424
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
@@ -35,6 +35,11 @@ final class ArrayDimFetchToMethodCallRector extends AbstractRector implements Co
3535
*/
3636
private array $arrayDimFetchToMethodCalls;
3737

38+
public function __construct(
39+
private readonly ContextAnalyzer $contextAnalyzer
40+
) {
41+
}
42+
3843
public function getRuleDefinition(): RuleDefinition
3944
{
4045
return new RuleDefinition('Change array dim fetch to method call', [
@@ -86,11 +91,7 @@ public function refactor(Node $node): array|Expr|null|int
8691
}
8792

8893
// is part of assign, skip
89-
if ($node->getAttribute(AttributeKey::IS_BEING_ASSIGNED)) {
90-
return null;
91-
}
92-
93-
if ($node->getAttribute(AttributeKey::IS_ASSIGN_OP_VAR)) {
94+
if ($this->contextAnalyzer->isLeftPartOfAssign($node)) {
9495
return null;
9596
}
9697

0 commit comments

Comments
 (0)