[CodeQuality] Fixes #5844 Skip ChangeArrayPushToArrayAssignRector on not in expression (#5845)

This commit is contained in:
Abdul Malik Ikhsan 2021-03-14 23:15:38 +07:00 committed by GitHub
parent fb8b9c1e75
commit a65d5de82f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<?php
namespace Rector\Tests\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector\Fixture;
final class SkipArrayPushNotInExpression
{
public function run()
{
$tagstack = array();
$tag = 'a';
$stacksize = array_push( $tagstack, $tag );
}
}

View File

@ -11,6 +11,7 @@ use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -73,6 +74,11 @@ CODE_SAMPLE
return null;
}
$parent = $node->getAttribute(AttributeKey::PARENT_NODE);
if (! $parent instanceof Expression) {
return null;
}
$arrayDimFetch = new ArrayDimFetch($node->args[0]->value);
$position = 1;