Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rectorphp/rector-src@c3e0ff3 [CodeQuality] Skip static variable on SimplifyUselessVariableRector (#630)
- Loading branch information
1 parent
b2c929a
commit 4cda207
Showing
8 changed files
with
73 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
namespace Rector\Core\NodeAnalyzer; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\Variable; | ||
use PhpParser\Node\Stmt\Static_; | ||
use Rector\Core\PhpParser\Comparing\NodeComparator; | ||
use Rector\Core\PhpParser\Node\BetterNodeFinder; | ||
final class VariableAnalyzer | ||
{ | ||
/** | ||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder | ||
*/ | ||
private $betterNodeFinder; | ||
/** | ||
* @var \Rector\Core\PhpParser\Comparing\NodeComparator | ||
*/ | ||
private $nodeComparator; | ||
public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $betterNodeFinder, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator) | ||
{ | ||
$this->betterNodeFinder = $betterNodeFinder; | ||
$this->nodeComparator = $nodeComparator; | ||
} | ||
public function isStatic(\PhpParser\Node\Expr\Variable $variable) : bool | ||
{ | ||
return (bool) $this->betterNodeFinder->findFirstPreviousOfNode($variable, function (\PhpParser\Node $n) use($variable) : bool { | ||
if (!$n instanceof \PhpParser\Node\Stmt\Static_) { | ||
return \false; | ||
} | ||
foreach ($n->vars as $staticVar) { | ||
if ($this->nodeComparator->areNodesEqual($staticVar->var, $variable)) { | ||
return \true; | ||
} | ||
} | ||
return \false; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters