Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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', [
Expand Down Expand Up @@ -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;
}

Expand Down