Skip to content

Commit

Permalink
Updated Rector to commit 05f832313c704757b3ff3925f6c0da45b5fb3cc7
Browse files Browse the repository at this point in the history
rectorphp/rector-src@05f8323 [AttributeKey] Drop statementDepth attribute (#6249)
  • Loading branch information
TomasVotruba committed Aug 22, 2024
1 parent afeb012 commit 0981ded
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 33 deletions.
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 = 'e3ad355409775a85349aed5ba8e803b7a93fc4dc';
public const PACKAGE_VERSION = '05f832313c704757b3ff3925f6c0da45b5fb3cc7';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-08-22 13:30:44';
public const RELEASE_DATE = '2024-08-22 21:16:19';
/**
* @var int
*/
Expand Down
4 changes: 0 additions & 4 deletions src/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ final class AttributeKey
* @var string
*/
public const IS_MULTI_ASSIGN = 'is_multi_assign';
/**
* @var string
*/
public const STATEMENT_DEPTH = 'statementDepth';
/**
* @var string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,12 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\NodeVisitorAbstract;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
final class StmtKeyNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
{
/**
* @param Node[] $nodes
*/
public function beforeTraverse(array $nodes) : ?array
{
if ($nodes === []) {
return null;
}
if (!$nodes[0] instanceof Declare_ && !$nodes[0] instanceof Namespace_) {
return null;
}
// on target node or no other root stmt, eg: only namespace without declare, no need to index
if (\count($nodes) === 1) {
return null;
}
// ensure statement depth is 0 to avoid declare in deep statements
// eg: declare(ticks=1) @see https://www.php.net/manual/en/control-structures.declare.php#123674
$statementDepth = $nodes[0]->getAttribute(AttributeKey::STATEMENT_DEPTH);
if ($statementDepth > 0 || $statementDepth === null) {
return null;
}
foreach ($nodes as $key => $node) {
$node->setAttribute(AttributeKey::STMT_KEY, $key);
}
return $nodes;
}
public function enterNode(Node $node) : ?Node
{
if (!$node instanceof StmtsAwareInterface && !$node instanceof ClassLike && !$node instanceof Declare_) {
Expand Down

0 comments on commit 0981ded

Please sign in to comment.