TokenEmulator.php 819 B

123456789101112131415161718192021222324252627282930
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Lexer\TokenEmulator;
  3. use PhpParser\PhpVersion;
  4. use PhpParser\Token;
  5. /** @internal */
  6. abstract class TokenEmulator {
  7. abstract public function getPhpVersion(): PhpVersion;
  8. abstract public function isEmulationNeeded(string $code): bool;
  9. /**
  10. * @param Token[] $tokens Original tokens
  11. * @return Token[] Modified Tokens
  12. */
  13. abstract public function emulate(string $code, array $tokens): array;
  14. /**
  15. * @param Token[] $tokens Original tokens
  16. * @return Token[] Modified Tokens
  17. */
  18. abstract public function reverseEmulate(string $code, array $tokens): array;
  19. /** @param array{int, string, string}[] $patches */
  20. public function preprocessCode(string $code, array &$patches): string {
  21. return $code;
  22. }
  23. }