Skip to content

Commit

Permalink
Updated Rector to commit 0c2185fbbdf245ac5246096dac79c231ead76cb7
Browse files Browse the repository at this point in the history
rectorphp/rector-src@0c2185f Add unit test for reindex stmt_key before refactor() called (#6613)
  • Loading branch information
TomasVotruba committed Dec 19, 2024
1 parent b0043cf commit 91d3d77
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 39 deletions.
50 changes: 29 additions & 21 deletions src/Application/NodeAttributeReIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,37 @@
use Rector\NodeTypeResolver\Node\AttributeKey;
final class NodeAttributeReIndexer
{
public static function reIndexStmtKeyNodeAttributes(Node $node) : ?Node
{
if (!$node instanceof StmtsAwareInterface && !$node instanceof ClassLike && !$node instanceof Declare_) {
return null;
}
if ($node->stmts === null) {
return null;
}
$node->stmts = \array_values($node->stmts);
// re-index stmt key under current node
foreach ($node->stmts as $key => $childStmt) {
$childStmt->setAttribute(AttributeKey::STMT_KEY, $key);
}
return $node;
}
public static function reIndexNodeAttributes(Node $node) : ?Node
{
if (($node instanceof StmtsAwareInterface || $node instanceof ClassLike || $node instanceof Declare_) && $node->stmts !== null) {
$node->stmts = \array_values($node->stmts);
// re-index stmt key under current node
foreach ($node->stmts as $key => $childStmt) {
$childStmt->setAttribute(AttributeKey::STMT_KEY, $key);
}
if ($node instanceof If_) {
$node->elseifs = \array_values($node->elseifs);
return $node;
}
if ($node instanceof TryCatch) {
$node->catches = \array_values($node->catches);
return $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 $node;
self::reIndexStmtKeyNodeAttributes($node);
if ($node instanceof If_) {
$node->elseifs = \array_values($node->elseifs);
return $node;
}
if ($node instanceof TryCatch) {
$node->catches = \array_values($node->catches);
return $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 $node;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '3e414f34039da79932322ed6e1f906454ab8c366';
public const PACKAGE_VERSION = '0c2185fbbdf245ac5246096dac79c231ead76cb7';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-12-19 05:25:16';
public const RELEASE_DATE = '2024-12-19 11:25:39';
/**
* @var int
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,13 @@
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;

use PhpParser\Node;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\NodeVisitorAbstract;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Application\NodeAttributeReIndexer;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
final class StmtKeyNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
{
public function enterNode(Node $node) : ?Node
{
if (!$node instanceof StmtsAwareInterface && !$node instanceof ClassLike && !$node instanceof Declare_) {
return null;
}
if ($node->stmts === null) {
return null;
}
$node->stmts = \array_values($node->stmts);
// re-index stmt key under current node
foreach ($node->stmts as $key => $childStmt) {
$childStmt->setAttribute(AttributeKey::STMT_KEY, $key);
}
return null;
return NodeAttributeReIndexer::reIndexStmtKeyNodeAttributes($node);
}
}

0 comments on commit 91d3d77

Please sign in to comment.