Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AsymmetricVisibilityTokenEmulator.php

function AsymmetricVisibilityTokenEmulator::emulate

Overrides TokenEmulator::emulate

File

vendor/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/AsymmetricVisibilityTokenEmulator.php, line 19

Class

AsymmetricVisibilityTokenEmulator

Namespace

PhpParser\Lexer\TokenEmulator

Code

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;
}
RSS feed
Powered by Drupal