You are here

public static function Twig_Error_Syntax::computeAlternatives in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Error/Syntax.php \Twig_Error_Syntax::computeAlternatives()

@internal

To be merged with the addSuggestions() method in 2.0.

2 calls to Twig_Error_Syntax::computeAlternatives()
Twig_Environment::computeAlternatives in vendor/twig/twig/lib/Twig/Environment.php
Twig_Error_Syntax::addSuggestions in vendor/twig/twig/lib/Twig/Error/Syntax.php
Tweaks the error message to include suggestions.

File

vendor/twig/twig/lib/Twig/Error/Syntax.php, line 40

Class

Twig_Error_Syntax
Exception thrown when a syntax error occurs during lexing or parsing of a template.

Code

public static function computeAlternatives($name, $items) {
  $alternatives = array();
  foreach ($items as $item) {
    $lev = levenshtein($name, $item);
    if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
      $alternatives[$item] = $lev;
    }
  }
  asort($alternatives);
  return array_keys($alternatives);
}