ReadonlyTokenEmulator.php 905 B

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