diff --git a/lib/PhpParser/Token.php b/lib/PhpParser/Token.php index 6683310f16..47fbab4044 100644 --- a/lib/PhpParser/Token.php +++ b/lib/PhpParser/Token.php @@ -8,11 +8,14 @@ class Token extends Internal\TokenPolyfill { /** Get (exclusive) zero-based end position of the token. */ public function getEndPos(): int { - return $this->pos + \strlen($this->text); + return $this->pos < 0 ? $this->pos : $this->pos + \strlen($this->text); } /** Get 1-based end line number of the token. */ public function getEndLine(): int { + if ($this->line < 1 || !isset($this->text[1])) { + return $this->line; + } return $this->line + \substr_count($this->text, "\n"); } }