1<?php declare(strict_types=1); 2 3namespace PhpParser\Lexer\TokenEmulator; 4 5use PhpParser\PhpVersion; 6 7final 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 // Support "function readonly(" 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