Skip to content

Commit

Permalink
[Solid] Skip MoveVariableDeclarationNearReferenceRector when next sta…
Browse files Browse the repository at this point in the history
…tement has static call (#4914)

Co-authored-by: rector-bot <tomas@getrector.org>
  • Loading branch information
samsonasik and rector-bot committed Dec 18, 2020
1 parent 7ff76b8 commit f61ad67
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Do_;
Expand Down Expand Up @@ -209,6 +210,10 @@ private function getUsageInNextStmts(Expression $expression, Node $node): ?Varia
return null;
}

if ($this->hasStaticCall($next)) {
return null;
}

$countFound = $this->getCountFound($next, $node);
if ($countFound === 0 || $countFound >= 2) {
return null;
Expand Down Expand Up @@ -248,6 +253,13 @@ private function mayBeArrayDimFetch(Node $node): Node
return $node;
}

private function hasStaticCall(Node $node): bool
{
return (bool) $this->betterNodeFinder->findFirst($node, function (Node $n): bool {
return $n instanceof StaticCall;
});
}

private function getCountFound(Node $node, Variable $variable): int
{
$countFound = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\SOLID\Tests\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

class SkipUsageInStaticCall
{
function myMethod()
{
$crawler = $kernelBrowser->request('GET', '/');
self::assertResponseIsSuccessful();
self::assertStringContainsString('Hello World', $crawler->filter('h1, h2, h3')->text());
}
}
?>

0 comments on commit f61ad67

Please sign in to comment.