Skip to content

Commit 09691fc

Browse files
staabmnikic
authored andcommitted
Prevent off-by-one errors in line-number related methods
1 parent 1396767 commit 09691fc

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

lib/PhpParser/Comment.php

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function getText(): string {
4646
* Gets the line number the comment started on.
4747
*
4848
* @return int Line number (or -1 if not available)
49+
* @phpstan-return -1|positive-int
4950
*/
5051
public function getStartLine(): int {
5152
return $this->startLine;
@@ -73,6 +74,7 @@ public function getStartTokenPos(): int {
7374
* Gets the line number the comment ends on.
7475
*
7576
* @return int Line number (or -1 if not available)
77+
* @phpstan-return -1|positive-int
7678
*/
7779
public function getEndLine(): int {
7880
return $this->endLine;

lib/PhpParser/Error.php

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function getRawMessage(): string {
3232
* Gets the line the error starts in.
3333
*
3434
* @return int Error start line
35+
* @phpstan-return -1|positive-int
3536
*/
3637
public function getStartLine(): int {
3738
return $this->attributes['startLine'] ?? -1;
@@ -41,6 +42,7 @@ public function getStartLine(): int {
4142
* Gets the line the error ends in.
4243
*
4344
* @return int Error end line
45+
* @phpstan-return -1|positive-int
4446
*/
4547
public function getEndLine(): int {
4648
return $this->attributes['endLine'] ?? -1;

lib/PhpParser/Node.php

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function getSubNodeNames(): array;
2121
* Gets line the node started in (alias of getStartLine).
2222
*
2323
* @return int Start line (or -1 if not available)
24+
* @phpstan-return -1|positive-int
2425
*
2526
* @deprecated Use getStartLine() instead
2627
*/
@@ -32,6 +33,7 @@ public function getLine(): int;
3233
* Requires the 'startLine' attribute to be enabled in the lexer (enabled by default).
3334
*
3435
* @return int Start line (or -1 if not available)
36+
* @phpstan-return -1|positive-int
3537
*/
3638
public function getStartLine(): int;
3739

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

lib/PhpParser/NodeAbstract.php

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function __construct(array $attributes = []) {
1919
* Gets line the node started in (alias of getStartLine).
2020
*
2121
* @return int Start line (or -1 if not available)
22+
* @phpstan-return -1|positive-int
2223
*/
2324
public function getLine(): int {
2425
return $this->attributes['startLine'] ?? -1;
@@ -30,6 +31,7 @@ public function getLine(): int {
3031
* Requires the 'startLine' attribute to be enabled in the lexer (enabled by default).
3132
*
3233
* @return int Start line (or -1 if not available)
34+
* @phpstan-return -1|positive-int
3335
*/
3436
public function getStartLine(): int {
3537
return $this->attributes['startLine'] ?? -1;
@@ -41,6 +43,7 @@ public function getStartLine(): int {
4143
* Requires the 'endLine' attribute to be enabled in the lexer (enabled by default).
4244
*
4345
* @return int End line (or -1 if not available)
46+
* @phpstan-return -1|positive-int
4447
*/
4548
public function getEndLine(): int {
4649
return $this->attributes['endLine'] ?? -1;

0 commit comments

Comments
 (0)