You are here

protected function Twig_Extension_Core::getTestName in Translation template extractor 6.3

1 call to Twig_Extension_Core::getTestName()
Twig_Extension_Core::parseTestExpression in vendor/Twig/Extension/Core.php

File

vendor/Twig/Extension/Core.php, line 311

Class

Twig_Extension_Core

Code

protected function getTestName(Twig_Parser $parser, $line) {
  $stream = $parser
    ->getStream();
  $name = $stream
    ->expect(Twig_Token::NAME_TYPE)
    ->getValue();
  $env = $parser
    ->getEnvironment();
  $testMap = $env
    ->getTests();
  if (isset($testMap[$name])) {
    return $name;
  }
  if ($stream
    ->test(Twig_Token::NAME_TYPE)) {

    // try 2-words tests
    $name = $name . ' ' . $parser
      ->getCurrentToken()
      ->getValue();
    if (isset($testMap[$name])) {
      $parser
        ->getStream()
        ->next();
      return $name;
    }
  }
  $message = sprintf('The test "%s" does not exist', $name);
  if ($alternatives = $env
    ->computeAlternatives($name, array_keys($testMap))) {
    $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
  }
  throw new Twig_Error_Syntax($message, $line, $parser
    ->getFilename());
}