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

Breadcrumb

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

function AsymmetricVisibilityTokenEmulator::reverseEmulate

Overrides TokenEmulator::reverseEmulate

File

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

Class

AsymmetricVisibilityTokenEmulator

Namespace

PhpParser\Lexer\TokenEmulator

Code

public function reverseEmulate(string $code, array $tokens) : array {
    $reverseMap = [
        \T_PUBLIC_SET => \T_PUBLIC,
        \T_PROTECTED_SET => \T_PROTECTED,
        \T_PRIVATE_SET => \T_PRIVATE,
    ];
    for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
        $token = $tokens[$i];
        if (isset($reverseMap[$token->id]) && \preg_match('/(public|protected|private)\\((set)\\)/i', $token->text, $matches)) {
            [
                ,
                $modifier,
                $set,
            ] = $matches;
            $modifierLen = \strlen($modifier);
            array_splice($tokens, $i, 1, [
                new Token($reverseMap[$token->id], $modifier, $token->line, $token->pos),
                new Token(\ord('('), '(', $token->line, $token->pos + $modifierLen),
                new Token(\T_STRING, $set, $token->line, $token->pos + $modifierLen + 1),
                new Token(\ord(')'), ')', $token->line, $token->pos + $modifierLen + 4),
            ]);
            $i += 3;
            $c += 3;
        }
    }
    return $tokens;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal