| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace PhpParser\Lexer\TokenEmulator; |
| 4: | |
| 5: | use PhpParser\PhpVersion; |
| 6: | |
| 7: | final class ReadonlyTokenEmulator extends KeywordEmulator { |
| 8: | public function getPhpVersion(): PhpVersion { |
| 9: | return PhpVersion::fromComponents(8, 1); |
| 10: | } |
| 11: | |
| 12: | public function getKeywordString(): string { |
| 13: | return 'readonly'; |
| 14: | } |
| 15: | |
| 16: | public function getKeywordToken(): int { |
| 17: | return \T_READONLY; |
| 18: | } |
| 19: | |
| 20: | protected function isKeywordContext(array $tokens, int $pos): bool { |
| 21: | if (!parent::isKeywordContext($tokens, $pos)) { |
| 22: | return false; |
| 23: | } |
| 24: | |
| 25: | return !(isset($tokens[$pos + 1]) && |
| 26: | ($tokens[$pos + 1]->text === '(' || |
| 27: | ($tokens[$pos + 1]->id === \T_WHITESPACE && |
| 28: | isset($tokens[$pos + 2]) && |
| 29: | $tokens[$pos + 2]->text === '('))); |
| 30: | } |
| 31: | } |
| 32: | |