function AsymmetricVisibilityTokenEmulator::emulate
Overrides TokenEmulator::emulate
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ Lexer/ TokenEmulator/ AsymmetricVisibilityTokenEmulator.php, line 19
Class
Namespace
PhpParser\Lexer\TokenEmulatorCode
public function emulate(string $code, array $tokens) : array {
$map = [
\T_PUBLIC => \T_PUBLIC_SET,
\T_PROTECTED => \T_PROTECTED_SET,
\T_PRIVATE => \T_PRIVATE_SET,
];
for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
$token = $tokens[$i];
if (isset($map[$token->id]) && $i + 3 < $c && $tokens[$i + 1]->text === '(' && $tokens[$i + 2]->id === \T_STRING && \strtolower($tokens[$i + 2]->text) === 'set' && $tokens[$i + 3]->text === ')' && $this->isKeywordContext($tokens, $i)) {
array_splice($tokens, $i, 4, [
new Token($map[$token->id], $token->text . '(' . $tokens[$i + 2]->text . ')', $token->line, $token->pos),
]);
$c -= 3;
}
}
return $tokens;
}