mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit d603b00818cfabc8aa1699b1154145e68bdb60a0
d603b00818
Remove PARENT_NODE from RemoveUnusedVariableAssignRector (#3935)
This commit is contained in:
parent
ad4182dc96
commit
ee06436c96
@ -6,27 +6,18 @@ namespace Rector\DeadCode\Rector\Assign;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\CallLike;
|
||||
use PhpParser\Node\Expr\Cast;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\NullsafeMethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Include_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Php\ReservedKeywordAnalyzer;
|
||||
use Rector\Core\PhpParser\Comparing\ConditionSearcher;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNextNodeAnalyzer;
|
||||
use Rector\DeadCode\NodeAnalyzer\UsedVariableNameAnalyzer;
|
||||
use Rector\DeadCode\SideEffect\SideEffectNodeDetector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Php74\Tokenizer\FollowedByCurlyBracketAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
@ -39,39 +30,15 @@ final class RemoveUnusedVariableAssignRector extends AbstractScopeAwareRector
|
||||
* @var \Rector\Core\Php\ReservedKeywordAnalyzer
|
||||
*/
|
||||
private $reservedKeywordAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Comparing\ConditionSearcher
|
||||
*/
|
||||
private $conditionSearcher;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DeadCode\NodeAnalyzer\UsedVariableNameAnalyzer
|
||||
*/
|
||||
private $usedVariableNameAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DeadCode\SideEffect\SideEffectNodeDetector
|
||||
*/
|
||||
private $sideEffectNodeDetector;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DeadCode\NodeAnalyzer\ExprUsedInNextNodeAnalyzer
|
||||
*/
|
||||
private $exprUsedInNextNodeAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Php74\Tokenizer\FollowedByCurlyBracketAnalyzer
|
||||
*/
|
||||
private $followedByCurlyBracketAnalyzer;
|
||||
public function __construct(ReservedKeywordAnalyzer $reservedKeywordAnalyzer, ConditionSearcher $conditionSearcher, UsedVariableNameAnalyzer $usedVariableNameAnalyzer, SideEffectNodeDetector $sideEffectNodeDetector, ExprUsedInNextNodeAnalyzer $exprUsedInNextNodeAnalyzer, FollowedByCurlyBracketAnalyzer $followedByCurlyBracketAnalyzer)
|
||||
public function __construct(ReservedKeywordAnalyzer $reservedKeywordAnalyzer, SideEffectNodeDetector $sideEffectNodeDetector)
|
||||
{
|
||||
$this->reservedKeywordAnalyzer = $reservedKeywordAnalyzer;
|
||||
$this->conditionSearcher = $conditionSearcher;
|
||||
$this->usedVariableNameAnalyzer = $usedVariableNameAnalyzer;
|
||||
$this->sideEffectNodeDetector = $sideEffectNodeDetector;
|
||||
$this->exprUsedInNextNodeAnalyzer = $exprUsedInNextNodeAnalyzer;
|
||||
$this->followedByCurlyBracketAnalyzer = $followedByCurlyBracketAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
@ -99,33 +66,48 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Assign::class];
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
/**
|
||||
* @param Assign $node
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?ClassMethod
|
||||
{
|
||||
if ($this->shouldSkip($node)) {
|
||||
$classMethodStmts = $node->stmts;
|
||||
if ($classMethodStmts === null) {
|
||||
return null;
|
||||
}
|
||||
$variable = $node->var;
|
||||
if (!$variable instanceof Variable) {
|
||||
// we cannot be sure here
|
||||
if ($this->containsCompactFuncCall($node)) {
|
||||
return null;
|
||||
}
|
||||
$variableName = $this->getName($variable);
|
||||
if ($variableName !== null && $this->reservedKeywordAnalyzer->isNativeVariable($variableName)) {
|
||||
if ($this->containsFileIncludes($node)) {
|
||||
return null;
|
||||
}
|
||||
// variable is used
|
||||
if ($this->isUsed($node, $variable, $scope)) {
|
||||
return $this->refactorUsedVariable($node, $scope);
|
||||
$assignedVariableNamesByStmtPosition = $this->resolvedAssignedVariablesByStmtPosition($classMethodStmts);
|
||||
$hasChanged = \false;
|
||||
foreach ($assignedVariableNamesByStmtPosition as $stmtPosition => $variableName) {
|
||||
if ($this->isVariableUsedInFollowingStmts($node, $stmtPosition, $variableName)) {
|
||||
continue;
|
||||
}
|
||||
/** @var Expression<Assign> $currentStmt */
|
||||
$currentStmt = $classMethodStmts[$stmtPosition];
|
||||
/** @var Assign $assign */
|
||||
$assign = $currentStmt->expr;
|
||||
/** @var Scope $assignScope */
|
||||
$assignScope = $assign->getAttribute(AttributeKey::SCOPE);
|
||||
if ($this->hasCallLikeInAssignExpr($assign, $assignScope)) {
|
||||
// clean safely
|
||||
$cleanAssignedExpr = $this->cleanCastedExpr($assign->expr);
|
||||
$node->stmts[$stmtPosition] = new Expression($cleanAssignedExpr);
|
||||
} else {
|
||||
unset($node->stmts[$stmtPosition]);
|
||||
}
|
||||
$hasChanged = \true;
|
||||
}
|
||||
if ($this->hasCallLikeInAssignExpr($node->expr, $scope)) {
|
||||
// keep the expr, can have side effect
|
||||
return $this->cleanCastedExpr($node->expr);
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
$this->removeNode($node);
|
||||
return null;
|
||||
}
|
||||
private function cleanCastedExpr(Expr $expr) : Expr
|
||||
@ -133,8 +115,7 @@ CODE_SAMPLE
|
||||
if (!$expr instanceof Cast) {
|
||||
return $expr;
|
||||
}
|
||||
$castedExpr = $expr->expr;
|
||||
return $this->cleanCastedExpr($castedExpr);
|
||||
return $this->cleanCastedExpr($expr->expr);
|
||||
}
|
||||
private function hasCallLikeInAssignExpr(Expr $expr, Scope $scope) : bool
|
||||
{
|
||||
@ -142,97 +123,71 @@ CODE_SAMPLE
|
||||
return $this->sideEffectNodeDetector->detectCallExpr($subNode, $scope);
|
||||
});
|
||||
}
|
||||
private function shouldSkip(Assign $assign) : bool
|
||||
private function isVariableUsedInFollowingStmts(ClassMethod $classMethod, int $assignStmtPosition, string $variableName) : bool
|
||||
{
|
||||
$classMethod = $this->betterNodeFinder->findParentType($assign, ClassMethod::class);
|
||||
if (!$classMethod instanceof FunctionLike) {
|
||||
return \true;
|
||||
}
|
||||
$variable = $assign->var;
|
||||
if (!$variable instanceof Variable) {
|
||||
return \true;
|
||||
}
|
||||
$parentNode = $assign->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (!$parentNode instanceof Expression) {
|
||||
return \true;
|
||||
}
|
||||
$originalNode = $parentNode->getAttribute(AttributeKey::ORIGINAL_NODE);
|
||||
if (!$originalNode instanceof Node) {
|
||||
return \true;
|
||||
}
|
||||
if (!$variable->name instanceof Variable) {
|
||||
return $this->followedByCurlyBracketAnalyzer->isFollowed($this->file, $variable);
|
||||
}
|
||||
return (bool) $this->betterNodeFinder->findFirstNext($assign, static function (Node $node) : bool {
|
||||
return $node instanceof Variable;
|
||||
});
|
||||
}
|
||||
private function isUsed(Assign $assign, Variable $variable, Scope $scope) : bool
|
||||
{
|
||||
$isUsedPrev = $scope->hasVariableType((string) $this->getName($variable))->yes();
|
||||
if ($isUsedPrev) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->exprUsedInNextNodeAnalyzer->isUsed($variable)) {
|
||||
return \true;
|
||||
}
|
||||
/** @var FuncCall|MethodCall|New_|NullsafeMethodCall|StaticCall $expr */
|
||||
$expr = $assign->expr;
|
||||
if (!$this->sideEffectNodeDetector->detectCallExpr($expr, $scope)) {
|
||||
if ($classMethod->stmts === null) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isUsedInAssignExpr($expr, $assign, $scope);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\CallLike|\PhpParser\Node\Expr $expr
|
||||
*/
|
||||
private function isUsedInAssignExpr($expr, Assign $assign, Scope $scope) : bool
|
||||
{
|
||||
if (!$expr instanceof CallLike) {
|
||||
return $this->isUsedInPreviousAssign($assign, $expr, $scope);
|
||||
}
|
||||
if ($expr->isFirstClassCallable()) {
|
||||
return \false;
|
||||
}
|
||||
foreach ($expr->getArgs() as $arg) {
|
||||
$variable = $arg->value;
|
||||
if ($this->isUsedInPreviousAssign($assign, $variable, $scope)) {
|
||||
foreach ($classMethod->stmts as $key => $stmt) {
|
||||
// do not look yet
|
||||
if ($key <= $assignStmtPosition) {
|
||||
continue;
|
||||
}
|
||||
$stmtScope = $stmt->getAttribute(AttributeKey::SCOPE);
|
||||
if (!$stmtScope instanceof Scope) {
|
||||
continue;
|
||||
}
|
||||
$foundVariable = $this->betterNodeFinder->findVariableOfName($stmt, $variableName);
|
||||
if ($foundVariable instanceof Variable) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function isUsedInPreviousAssign(Assign $assign, Expr $expr, Scope $scope) : bool
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node $node
|
||||
*/
|
||||
private function containsCompactFuncCall($node) : bool
|
||||
{
|
||||
if (!$expr instanceof Variable) {
|
||||
return \false;
|
||||
}
|
||||
$previousAssign = $this->betterNodeFinder->findFirstPrevious($assign, function (Node $node) use($expr) : bool {
|
||||
return $node instanceof Assign && $this->usedVariableNameAnalyzer->isVariableNamed($node->var, $expr);
|
||||
});
|
||||
if ($previousAssign instanceof Assign) {
|
||||
return $this->isUsed($assign, $expr, $scope);
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function refactorUsedVariable(Assign $assign, Scope $scope) : ?\PhpParser\Node\Expr
|
||||
{
|
||||
$parentNode = $assign->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (!$parentNode instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
$node = $this->betterNodeFinder->resolveNextNode($parentNode);
|
||||
// check if next node is if
|
||||
if (!$node instanceof If_) {
|
||||
if ($assign->var instanceof Variable && !$scope->hasVariableType((string) $this->getName($assign->var))->yes() && !$this->exprUsedInNextNodeAnalyzer->isUsed($assign->var)) {
|
||||
return $this->cleanCastedExpr($assign->expr);
|
||||
$compactFuncCall = $this->betterNodeFinder->findFirst($node, function (Node $node) : bool {
|
||||
if (!$node instanceof FuncCall) {
|
||||
return \false;
|
||||
}
|
||||
return null;
|
||||
return $this->isName($node, 'compact');
|
||||
});
|
||||
return $compactFuncCall instanceof FuncCall;
|
||||
}
|
||||
private function containsFileIncludes(ClassMethod $classMethod) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findInstancesOf($classMethod, [Include_::class]);
|
||||
}
|
||||
/**
|
||||
* @param array<int, Stmt> $stmts
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function resolvedAssignedVariablesByStmtPosition(array $stmts) : array
|
||||
{
|
||||
$assignedVariableNamesByStmtPosition = [];
|
||||
foreach ($stmts as $key => $stmt) {
|
||||
if (!$stmt instanceof Expression) {
|
||||
continue;
|
||||
}
|
||||
if (!$stmt->expr instanceof Assign) {
|
||||
continue;
|
||||
}
|
||||
$assign = $stmt->expr;
|
||||
if (!$assign->var instanceof Variable) {
|
||||
continue;
|
||||
}
|
||||
$variableName = $this->getName($assign->var);
|
||||
if (!\is_string($variableName)) {
|
||||
continue;
|
||||
}
|
||||
if ($this->reservedKeywordAnalyzer->isNativeVariable($variableName)) {
|
||||
continue;
|
||||
}
|
||||
$assignedVariableNamesByStmtPosition[$key] = $variableName;
|
||||
}
|
||||
if ($this->conditionSearcher->hasIfAndElseForVariableRedeclaration($assign, $node)) {
|
||||
$this->removeNode($assign);
|
||||
return $assign;
|
||||
}
|
||||
return null;
|
||||
return $assignedVariableNamesByStmtPosition;
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ namespace Rector\Php74\Rector\ArrayDimFetch;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\Application\File;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Php74\Tokenizer\FollowedByCurlyBracketAnalyzer;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
@ -18,15 +18,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
*/
|
||||
final class CurlyToSquareBracketArrayStringRector extends AbstractRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Php74\Tokenizer\FollowedByCurlyBracketAnalyzer
|
||||
*/
|
||||
private $followedByCurlyBracketAnalyzer;
|
||||
public function __construct(FollowedByCurlyBracketAnalyzer $followedByCurlyBracketAnalyzer)
|
||||
{
|
||||
$this->followedByCurlyBracketAnalyzer = $followedByCurlyBracketAnalyzer;
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
return PhpVersionFeature::DEPRECATE_CURLY_BRACKET_ARRAY_STRING;
|
||||
@ -36,12 +27,14 @@ final class CurlyToSquareBracketArrayStringRector extends AbstractRector impleme
|
||||
return new RuleDefinition('Change curly based array and string to square bracket', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
$string = 'test';
|
||||
echo $string{0};
|
||||
|
||||
$array = ['test'];
|
||||
echo $array{0};
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
$string = 'test';
|
||||
echo $string[0];
|
||||
|
||||
$array = ['test'];
|
||||
echo $array[0];
|
||||
CODE_SAMPLE
|
||||
@ -59,11 +52,21 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->followedByCurlyBracketAnalyzer->isFollowed($this->file, $node)) {
|
||||
if (!$this->isFollowedByCurlyBracket($this->file, $node)) {
|
||||
return null;
|
||||
}
|
||||
// re-draw the ArrayDimFetch to use [] bracket
|
||||
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
|
||||
return $node;
|
||||
}
|
||||
private function isFollowedByCurlyBracket(File $file, ArrayDimFetch $arrayDimFetch) : bool
|
||||
{
|
||||
$oldTokens = $file->getOldTokens();
|
||||
$endTokenPost = $arrayDimFetch->getEndTokenPos();
|
||||
if (isset($oldTokens[$endTokenPost]) && $oldTokens[$endTokenPost] === '}') {
|
||||
$startTokenPost = $arrayDimFetch->getStartTokenPos();
|
||||
return !(isset($oldTokens[$startTokenPost][1]) && $oldTokens[$startTokenPost][1] === '${');
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Php74\Tokenizer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use Rector\Core\ValueObject\Application\File;
|
||||
final class FollowedByCurlyBracketAnalyzer
|
||||
{
|
||||
public function isFollowed(File $file, Node $node) : bool
|
||||
{
|
||||
$oldTokens = $file->getOldTokens();
|
||||
$endTokenPost = $node->getEndTokenPos();
|
||||
if (isset($oldTokens[$endTokenPost]) && $oldTokens[$endTokenPost] === '}') {
|
||||
$startTokenPost = $node->getStartTokenPos();
|
||||
return !(isset($oldTokens[$startTokenPost][1]) && $oldTokens[$startTokenPost][1] === '${');
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '8f3569e84677b4a29feb0af0788a0156086f921f';
|
||||
public const PACKAGE_VERSION = 'd603b00818cfabc8aa1699b1154145e68bdb60a0';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-23 01:55:14';
|
||||
public const RELEASE_DATE = '2023-05-23 13:32:59';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -15,7 +15,7 @@ final class RectorKernel
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const CACHE_KEY = 'v20';
|
||||
private const CACHE_KEY = 'v22';
|
||||
/**
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface|null
|
||||
*/
|
||||
|
@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\PhpParser\Comparing;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Else_;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
final class ConditionSearcher
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
|
||||
*/
|
||||
private $nodeComparator;
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeComparator = $nodeComparator;
|
||||
}
|
||||
public function hasIfAndElseForVariableRedeclaration(Assign $assign, If_ $if) : bool
|
||||
{
|
||||
if (!$if->else instanceof Else_) {
|
||||
return \false;
|
||||
}
|
||||
$ifElse = $if->else;
|
||||
/** @var Variable $varNode */
|
||||
$varNode = $assign->var;
|
||||
if (!$this->hasVariableRedeclaration($varNode, $if->stmts)) {
|
||||
return \false;
|
||||
}
|
||||
foreach ($if->elseifs as $elseifNode) {
|
||||
if (!$this->hasVariableRedeclaration($varNode, $elseifNode->stmts)) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
$isInCond = (bool) $this->betterNodeFinder->findFirst($if->cond, function (Node $subNode) use($varNode) : bool {
|
||||
return $this->nodeComparator->areNodesEqual($varNode, $subNode);
|
||||
});
|
||||
if ($isInCond) {
|
||||
return \false;
|
||||
}
|
||||
return $this->hasVariableRedeclaration($varNode, $ifElse->stmts);
|
||||
}
|
||||
/**
|
||||
* @param Stmt[] $stmts
|
||||
*/
|
||||
private function hasVariableRedeclaration(Variable $variable, array $stmts) : bool
|
||||
{
|
||||
foreach ($stmts as $stmt) {
|
||||
if ($this->hasVariableUsedInExpression($variable, $stmt)) {
|
||||
return \false;
|
||||
}
|
||||
if ($this->hasVariableDeclaration($variable, $stmt)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function hasVariableUsedInExpression(Variable $variable, Stmt $stmt) : bool
|
||||
{
|
||||
if ($stmt instanceof Expression) {
|
||||
$node = $stmt->expr instanceof Assign ? $stmt->expr->expr : $stmt->expr;
|
||||
} else {
|
||||
$node = $stmt;
|
||||
}
|
||||
return (bool) $this->betterNodeFinder->findFirst($node, function (Node $subNode) use($variable) : bool {
|
||||
return $this->nodeComparator->areNodesEqual($variable, $subNode);
|
||||
});
|
||||
}
|
||||
private function hasVariableDeclaration(Variable $variable, Stmt $stmt) : bool
|
||||
{
|
||||
if (!$stmt instanceof Expression) {
|
||||
return \false;
|
||||
}
|
||||
if (!$stmt->expr instanceof Assign) {
|
||||
return \false;
|
||||
}
|
||||
$assign = $stmt->expr;
|
||||
if (!$assign->var instanceof Variable) {
|
||||
return \false;
|
||||
}
|
||||
$assignedVariable = $assign->var;
|
||||
return $variable->name === $assignedVariable->name;
|
||||
}
|
||||
}
|
@ -513,6 +513,8 @@ final class BetterNodeFinder
|
||||
/**
|
||||
* @api
|
||||
*
|
||||
* @deprecated Use StmtsAwareInterface instead
|
||||
*
|
||||
* Resolve next node from any Node, eg: Expr, Identifier, Name, etc
|
||||
*/
|
||||
public function resolveNextNode(Node $node) : ?Node
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitbd1c9a152ba5ac575455804a7122ce5f::getLoader();
|
||||
return ComposerAutoloaderInit67af263d55e6ae38829253b8878b98ed::getLoader();
|
||||
|
2
vendor/composer/autoload_classmap.php
vendored
2
vendor/composer/autoload_classmap.php
vendored
@ -1502,7 +1502,6 @@ return array(
|
||||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverRegistry' => $baseDir . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverRegistry.php',
|
||||
'Rector\\Core\\PhpParser\\AstResolver' => $baseDir . '/src/PhpParser/AstResolver.php',
|
||||
'Rector\\Core\\PhpParser\\ClassLikeAstResolver' => $baseDir . '/src/PhpParser/ClassLikeAstResolver.php',
|
||||
'Rector\\Core\\PhpParser\\Comparing\\ConditionSearcher' => $baseDir . '/src/PhpParser/Comparing/ConditionSearcher.php',
|
||||
'Rector\\Core\\PhpParser\\Comparing\\NodeComparator' => $baseDir . '/src/PhpParser/Comparing/NodeComparator.php',
|
||||
'Rector\\Core\\PhpParser\\NodeFinder\\LocalConstantFinder' => $baseDir . '/src/PhpParser/NodeFinder/LocalConstantFinder.php',
|
||||
'Rector\\Core\\PhpParser\\NodeFinder\\LocalMethodCallFinder' => $baseDir . '/src/PhpParser/NodeFinder/LocalMethodCallFinder.php',
|
||||
@ -2249,7 +2248,6 @@ return array(
|
||||
'Rector\\Php74\\Rector\\Property\\RestoreDefaultNullToNullableTypePropertyRector' => $baseDir . '/rules/Php74/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector.php',
|
||||
'Rector\\Php74\\Rector\\StaticCall\\ExportToReflectionFunctionRector' => $baseDir . '/rules/Php74/Rector/StaticCall/ExportToReflectionFunctionRector.php',
|
||||
'Rector\\Php74\\Rector\\Ternary\\ParenthesizeNestedTernaryRector' => $baseDir . '/rules/Php74/Rector/Ternary/ParenthesizeNestedTernaryRector.php',
|
||||
'Rector\\Php74\\Tokenizer\\FollowedByCurlyBracketAnalyzer' => $baseDir . '/rules/Php74/Tokenizer/FollowedByCurlyBracketAnalyzer.php',
|
||||
'Rector\\Php74\\Tokenizer\\ParenthesizedNestedTernaryAnalyzer' => $baseDir . '/rules/Php74/Tokenizer/ParenthesizedNestedTernaryAnalyzer.php',
|
||||
'Rector\\Php80\\AttributeDecorator\\JMSAccesorOrderAttributeDecorator' => $baseDir . '/rules/Php80/AttributeDecorator/JMSAccesorOrderAttributeDecorator.php',
|
||||
'Rector\\Php80\\AttributeDecorator\\JMSAccessTypeAttributeDecorator' => $baseDir . '/rules/Php80/AttributeDecorator/JMSAccessTypeAttributeDecorator.php',
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitbd1c9a152ba5ac575455804a7122ce5f
|
||||
class ComposerAutoloaderInit67af263d55e6ae38829253b8878b98ed
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInitbd1c9a152ba5ac575455804a7122ce5f
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitbd1c9a152ba5ac575455804a7122ce5f', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit67af263d55e6ae38829253b8878b98ed', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitbd1c9a152ba5ac575455804a7122ce5f', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit67af263d55e6ae38829253b8878b98ed', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitbd1c9a152ba5ac575455804a7122ce5f::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit67af263d55e6ae38829253b8878b98ed::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitbd1c9a152ba5ac575455804a7122ce5f::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit67af263d55e6ae38829253b8878b98ed::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
10
vendor/composer/autoload_static.php
vendored
10
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitbd1c9a152ba5ac575455804a7122ce5f
|
||||
class ComposerStaticInit67af263d55e6ae38829253b8878b98ed
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -1744,7 +1744,6 @@ class ComposerStaticInitbd1c9a152ba5ac575455804a7122ce5f
|
||||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverRegistry' => __DIR__ . '/../..' . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverRegistry.php',
|
||||
'Rector\\Core\\PhpParser\\AstResolver' => __DIR__ . '/../..' . '/src/PhpParser/AstResolver.php',
|
||||
'Rector\\Core\\PhpParser\\ClassLikeAstResolver' => __DIR__ . '/../..' . '/src/PhpParser/ClassLikeAstResolver.php',
|
||||
'Rector\\Core\\PhpParser\\Comparing\\ConditionSearcher' => __DIR__ . '/../..' . '/src/PhpParser/Comparing/ConditionSearcher.php',
|
||||
'Rector\\Core\\PhpParser\\Comparing\\NodeComparator' => __DIR__ . '/../..' . '/src/PhpParser/Comparing/NodeComparator.php',
|
||||
'Rector\\Core\\PhpParser\\NodeFinder\\LocalConstantFinder' => __DIR__ . '/../..' . '/src/PhpParser/NodeFinder/LocalConstantFinder.php',
|
||||
'Rector\\Core\\PhpParser\\NodeFinder\\LocalMethodCallFinder' => __DIR__ . '/../..' . '/src/PhpParser/NodeFinder/LocalMethodCallFinder.php',
|
||||
@ -2491,7 +2490,6 @@ class ComposerStaticInitbd1c9a152ba5ac575455804a7122ce5f
|
||||
'Rector\\Php74\\Rector\\Property\\RestoreDefaultNullToNullableTypePropertyRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector.php',
|
||||
'Rector\\Php74\\Rector\\StaticCall\\ExportToReflectionFunctionRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/StaticCall/ExportToReflectionFunctionRector.php',
|
||||
'Rector\\Php74\\Rector\\Ternary\\ParenthesizeNestedTernaryRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/Ternary/ParenthesizeNestedTernaryRector.php',
|
||||
'Rector\\Php74\\Tokenizer\\FollowedByCurlyBracketAnalyzer' => __DIR__ . '/../..' . '/rules/Php74/Tokenizer/FollowedByCurlyBracketAnalyzer.php',
|
||||
'Rector\\Php74\\Tokenizer\\ParenthesizedNestedTernaryAnalyzer' => __DIR__ . '/../..' . '/rules/Php74/Tokenizer/ParenthesizedNestedTernaryAnalyzer.php',
|
||||
'Rector\\Php80\\AttributeDecorator\\JMSAccesorOrderAttributeDecorator' => __DIR__ . '/../..' . '/rules/Php80/AttributeDecorator/JMSAccesorOrderAttributeDecorator.php',
|
||||
'Rector\\Php80\\AttributeDecorator\\JMSAccessTypeAttributeDecorator' => __DIR__ . '/../..' . '/rules/Php80/AttributeDecorator/JMSAccessTypeAttributeDecorator.php',
|
||||
@ -3111,9 +3109,9 @@ class ComposerStaticInitbd1c9a152ba5ac575455804a7122ce5f
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitbd1c9a152ba5ac575455804a7122ce5f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitbd1c9a152ba5ac575455804a7122ce5f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitbd1c9a152ba5ac575455804a7122ce5f::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit67af263d55e6ae38829253b8878b98ed::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit67af263d55e6ae38829253b8878b98ed::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit67af263d55e6ae38829253b8878b98ed::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user