Skip to content

Commit

Permalink
Use PHP-Parser start and end lines where we have both.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Nov 3, 2023
1 parent eed27c3 commit ff4a56e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/CodeCleaner/ImplicitReturnPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ private function addImplicitReturn(array $nodes): array
} elseif ($last instanceof Expr && !($last instanceof Exit_)) {
// @codeCoverageIgnoreStart
$nodes[\count($nodes) - 1] = new Return_($last, [
'startLine' => $last->getLine(),
'endLine' => $last->getLine(),
'startLine' => $last->getStartLine(),
'endLine' => $last->getEndLine(),
]);
// @codeCoverageIgnoreEnd
} elseif ($last instanceof Expression && !($last->expr instanceof Exit_)) {
$nodes[\count($nodes) - 1] = new Return_($last->expr, [
'startLine' => $last->getLine(),
'endLine' => $last->getLine(),
'startLine' => $last->getStartLine(),
'endLine' => $last->getEndLine(),
]);
} elseif ($last instanceof Namespace_) {
$last->stmts = $this->addImplicitReturn($last->stmts);
Expand Down
4 changes: 2 additions & 2 deletions src/CodeCleaner/LabelContextPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function enterNode(Node $node)
}

if ($node instanceof Goto_) {
$this->labelGotos[\strtolower($node->name)] = $node->getLine();
$this->labelGotos[\strtolower($node->name)] = $node->getStartLine();
} elseif ($node instanceof Label) {
$this->labelDeclarations[\strtolower($node->name)] = $node->getLine();
$this->labelDeclarations[\strtolower($node->name)] = $node->getStartLine();
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/CodeCleaner/ListPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public function enterNode(Node $node)
$items = isset($node->var->items) ? $node->var->items : $node->var->vars;

if ($items === [] || $items === [null]) {
throw new ParseErrorException('Cannot use empty list', $node->var->getLine());
throw new ParseErrorException('Cannot use empty list', [
'startLine' => $node->var->getStartLine(),
'endLine' => $node->var->getEndLine(),
]);
}

$itemFound = false;
Expand All @@ -65,7 +68,10 @@ public function enterNode(Node $node)

if (!self::isValidArrayItem($item)) {
$msg = 'Assignments can only happen to writable values';
throw new ParseErrorException($msg, $item->getLine());
throw new ParseErrorException($msg, [
'startLine' => $item->getStartLine(),
'endLine' => $item->getEndLine(),
]);
}
}

Expand Down

0 comments on commit ff4a56e

Please sign in to comment.