Skip to content

Commit

Permalink
Prevent off-by-one errors in line-numer related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Mar 13, 2024
1 parent 1396767 commit 992edb8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/PhpParser/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function getText(): string {
* Gets the line number the comment started on.
*
* @return int Line number (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getStartLine(): int {
return $this->startLine;
Expand Down Expand Up @@ -73,6 +74,7 @@ public function getStartTokenPos(): int {
* Gets the line number the comment ends on.
*
* @return int Line number (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getEndLine(): int {
return $this->endLine;
Expand Down
2 changes: 2 additions & 0 deletions lib/PhpParser/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function getRawMessage(): string {
* Gets the line the error starts in.
*
* @return int Error start line
* @phpstan-return -1|positive-int
*/
public function getStartLine(): int {
return $this->attributes['startLine'] ?? -1;
Expand All @@ -41,6 +42,7 @@ public function getStartLine(): int {
* Gets the line the error ends in.
*
* @return int Error end line
* @phpstan-return -1|positive-int
*/
public function getEndLine(): int {
return $this->attributes['endLine'] ?? -1;
Expand Down
3 changes: 3 additions & 0 deletions lib/PhpParser/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function getSubNodeNames(): array;
* Gets line the node started in (alias of getStartLine).
*
* @return int Start line (or -1 if not available)
* @phpstan-return -1|positive-int
*
* @deprecated Use getStartLine() instead
*/
Expand All @@ -32,6 +33,7 @@ public function getLine(): int;
* Requires the 'startLine' attribute to be enabled in the lexer (enabled by default).
*
* @return int Start line (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getStartLine(): int;

Expand All @@ -41,6 +43,7 @@ public function getStartLine(): int;
* Requires the 'endLine' attribute to be enabled in the lexer (enabled by default).
*
* @return int End line (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getEndLine(): int;

Expand Down
3 changes: 3 additions & 0 deletions lib/PhpParser/NodeAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct(array $attributes = []) {
* Gets line the node started in (alias of getStartLine).
*
* @return int Start line (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getLine(): int {
return $this->attributes['startLine'] ?? -1;
Expand All @@ -30,6 +31,7 @@ public function getLine(): int {
* Requires the 'startLine' attribute to be enabled in the lexer (enabled by default).
*
* @return int Start line (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getStartLine(): int {
return $this->attributes['startLine'] ?? -1;
Expand All @@ -41,6 +43,7 @@ public function getStartLine(): int {
* Requires the 'endLine' attribute to be enabled in the lexer (enabled by default).
*
* @return int End line (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getEndLine(): int {
return $this->attributes['endLine'] ?? -1;
Expand Down

0 comments on commit 992edb8

Please sign in to comment.