Skip to content

Commit

Permalink
[Parser] Clean up BetterNodeFinder::findFirstInTopLevelStmtsAware() p…
Browse files Browse the repository at this point in the history
…aram type (#3906)
  • Loading branch information
samsonasik committed May 20, 2023
1 parent 20fce3b commit 32d2eed
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/PhpParser/Node/BetterNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,8 @@ private function resolveNewStmts(?Node $parentNode): array
/**
* @param callable(Node $node): bool $filter
*/
private function findFirstInTopLevelStmtsAware(
StmtsAwareInterface|ClassLike|Declare_ $stmtsAware,
callable $filter
): ?Node {
private function findFirstInTopLevelStmtsAware(StmtsAwareInterface $stmtsAware, callable $filter): ?Node
{
$nodes = [];

if ($stmtsAware instanceof Foreach_) {
Expand Down Expand Up @@ -771,7 +769,10 @@ private function resolveNextNodeFromOtherNode(Node $node): ?Node

$nextNode = $node instanceof Stmt
? null
: $this->findFirst($currentStmt, static fn (Node $subNode): bool => $subNode->getStartTokenPos() > $endTokenPos);
: $this->findFirst(
$currentStmt,
static fn (Node $subNode): bool => $subNode->getStartTokenPos() > $endTokenPos
);

if (! $nextNode instanceof Node) {
$parentNode = $currentStmt->getAttribute(AttributeKey::PARENT_NODE);
Expand Down Expand Up @@ -803,11 +804,11 @@ private function findFirstInlinedPrevious(Node $node, callable $filter, array $n
}

$currentStmtKey = $node->getAttribute(AttributeKey::STMT_KEY);
/** @var StmtsAwareInterface|ClassLike|Declare_ $parentNode */
if (! isset($parentNode->stmts[$currentStmtKey - 1])) {
if ($parentNode instanceof StmtsAwareInterface && ! isset($parentNode->stmts[$currentStmtKey - 1])) {
return $this->findFirstInTopLevelStmtsAware($parentNode, $filter);
}

/** @var StmtsAwareInterface|ClassLike|Declare_ $parentNode */
$previousNode = $parentNode->stmts[$currentStmtKey - 1] ?? null;
} else {
$previousNode = $this->resolvePreviousNodeFromOtherNode($node);
Expand Down

0 comments on commit 32d2eed

Please sign in to comment.