| @@ -25,9 +25,9 @@ | ||
| 25 | 25 | * @var string |
| 26 | 26 | */ |
| 27 | 27 | public $text; |
| 28 | 28 | /** |
| 29 | - * @var int | |
| 29 | + * @var -1|positive-int | |
| 30 | 30 | */ |
| 31 | 31 | public $line; |
| 32 | 32 | /** |
| 33 | 33 | * @var int |
| @@ -32,8 +32,11 @@ | ||
| 32 | 32 | /** |
| 33 | 33 | * @var int |
| 34 | 34 | */ |
| 35 | 35 | public $pos; |
| 36 | + /** | |
| 37 | + * @param -1|positive-int $line | |
| 38 | + */ | |
| 36 | 39 | public function __construct(int $id, string $text, int $line = -1, int $position = -1) |
| 37 | 40 | { |
| 38 | 41 | $this->id = $id; |
| 39 | 42 | $this->text = $text; |
| @@ -39,11 +42,11 @@ | ||
| 39 | 42 | $this->text = $text; |
| 40 | 43 | $this->line = $line; |
| 41 | 44 | $this->pos = $position; |
| 42 | 45 | } |
| 43 | - public function getTokenName() : ?string | |
| 46 | + public function getTokenName(): ?string | |
| 44 | 47 | { |
| 45 | - if ('UNKNOWN' === ($name = \token_name($this->id))) { | |
| 48 | + if ('UNKNOWN' === $name = token_name($this->id)) { | |
| 46 | 49 | $name = \strlen($this->text) > 1 || \ord($this->text) < 32 ? null : $this->text; |
| 47 | 50 | } |
| 48 | 51 | return $name; |
| 49 | 52 | } |
| @@ -49,9 +52,9 @@ | ||
| 49 | 52 | } |
| 50 | 53 | /** |
| 51 | 54 | * @param int|string|array $kind |
| 52 | 55 | */ |
| 53 | - public function is($kind) : bool | |
| 56 | + public function is($kind): bool | |
| 54 | 57 | { |
| 55 | 58 | foreach ((array) $kind as $value) { |
| 56 | 59 | if (\in_array($value, [$this->id, $this->text], \true)) { |
| 57 | 60 | return \true; |
| @@ -58,24 +61,24 @@ | ||
| 58 | 61 | } |
| 59 | 62 | } |
| 60 | 63 | return \false; |
| 61 | 64 | } |
| 62 | - public function isIgnorable() : bool | |
| 65 | + public function isIgnorable(): bool | |
| 63 | 66 | { |
| 64 | 67 | return \in_array($this->id, [\T_WHITESPACE, \T_COMMENT, \T_DOC_COMMENT, \T_OPEN_TAG], \true); |
| 65 | 68 | } |
| 66 | - public function __toString() : string | |
| 69 | + public function __toString(): string | |
| 67 | 70 | { |
| 68 | 71 | return (string) $this->text; |
| 69 | 72 | } |
| 70 | 73 | /** |
| 71 | - * @return static[] | |
| 74 | + * @return list<static> | |
| 72 | 75 | */ |
| 73 | - public static function tokenize(string $code, int $flags = 0) : array | |
| 76 | + public static function tokenize(string $code, int $flags = 0): array | |
| 74 | 77 | { |
| 75 | 78 | $line = 1; |
| 76 | 79 | $position = 0; |
| 77 | - $tokens = \token_get_all($code, $flags); | |
| 80 | + $tokens = token_get_all($code, $flags); | |
| 78 | 81 | foreach ($tokens as $index => $token) { |
| 79 | 82 | if (\is_string($token)) { |
| 80 | 83 | $id = \ord($token); |
| 81 | 84 | $text = $token; |