-
-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NodeTypeResolver] Re-index node attributes on refresh process
- Loading branch information
1 parent
6024d31
commit 3c2f735
Showing
6 changed files
with
72 additions
and
38 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
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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\PHPStan\NodeVisitor; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\CallLike; | ||
use PhpParser\Node\Expr\Closure; | ||
use PhpParser\Node\Expr\FuncCall; | ||
use PhpParser\Node\Expr\MethodCall; | ||
use PhpParser\Node\Expr\NullsafeMethodCall; | ||
use PhpParser\Node\Expr\StaticCall; | ||
use PhpParser\Node\FunctionLike; | ||
use PhpParser\Node\MatchArm; | ||
use PhpParser\Node\Stmt\If_; | ||
use PhpParser\Node\Stmt\Switch_; | ||
use PhpParser\Node\Stmt\TryCatch; | ||
use PhpParser\NodeVisitorAbstract; | ||
|
||
final class ReIndexNodeAttributeVisitor extends NodeVisitorAbstract | ||
{ | ||
public function enterNode(Node $node): ?Node | ||
{ | ||
if ($node instanceof FunctionLike) { | ||
/** @var ClassMethod|Function_|Closure $node */ | ||
$node->params = array_values($node->params); | ||
|
||
if ($node instanceof Closure) { | ||
$node->uses = array_values($node->uses); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
if ($node instanceof CallLike) { | ||
/** @var FuncCall|MethodCall|New_|NullsafeMethodCall|StaticCall $node */ | ||
$node->args = array_values($node->args); | ||
return null; | ||
} | ||
|
||
if ($node instanceof If_) { | ||
$node->elseifs = array_values($node->elseifs); | ||
return null; | ||
} | ||
|
||
if ($node instanceof TryCatch) { | ||
$node->catches = array_values($node->catches); | ||
return null; | ||
} | ||
|
||
if ($node instanceof Switch_) { | ||
$node->cases = array_values($node->cases); | ||
return null; | ||
} | ||
|
||
if ($node instanceof MatchArm && is_array($node->conds)) { | ||
$node->conds = array_values($node->conds); | ||
} | ||
|
||
return null; | ||
} | ||
} |
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