Skip to content

Commit

Permalink
[CodeQuality] Skip combine var with property fetch on InlineArrayRetu…
Browse files Browse the repository at this point in the history
…rnAssignRector (#5681)

* [CodeQuality] Skip combine var with property fetch on InlineArrayReturnAssignRector

* fix
  • Loading branch information
samsonasik committed Mar 3, 2024
1 parent c591bd2 commit 2846b01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector\Fixture;

final class SkipWithPropertyFetch
{
public function run($person2)
{
$person = [];

$person['name'] = 'Timmy';
$this->person['name'] = 'Back';

return $person;
}
}
Expand Up @@ -44,7 +44,7 @@ public function resolveFromStmtsAndVariable(array $stmts, Variable $variable): a
$assign = $stmtExpr;

$keyExpr = $this->matchKeyOnArrayDimFetchOfVariable($assign, $variable);
if ($keyExpr instanceof ArrayDimFetch) {
if ($assign->var instanceof ArrayDimFetch && $assign->var->var instanceof ArrayDimFetch) {
return [];
}

Expand All @@ -67,7 +67,7 @@ private function matchKeyOnArrayDimFetchOfVariable(Assign $assign, Variable $var
}

$arrayDimFetch = $assign->var;
if ($arrayDimFetch->var instanceof Variable && ! $this->nodeComparator->areNodesEqual($arrayDimFetch->var, $variable)) {
if (! $this->nodeComparator->areNodesEqual($arrayDimFetch->var, $variable)) {
return null;
}

Expand All @@ -80,10 +80,6 @@ private function matchKeyOnArrayDimFetchOfVariable(Assign $assign, Variable $var
return null;
}

if ($arrayDimFetch->var instanceof ArrayDimFetch) {
return $arrayDimFetch->var;
}

return $arrayDimFetch->dim;
}

Expand Down

0 comments on commit 2846b01

Please sign in to comment.