vendor/twig/twig/src/Error/SyntaxError.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Twig.
  4.  *
  5.  * (c) Fabien Potencier
  6.  * (c) Armin Ronacher
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Twig\Error;
  12. /**
  13.  * \Exception thrown when a syntax error occurs during lexing or parsing of a template.
  14.  *
  15.  * @author Fabien Potencier <fabien@symfony.com>
  16.  */
  17. class SyntaxError extends Error
  18. {
  19.     /**
  20.      * Tweaks the error message to include suggestions.
  21.      *
  22.      * @param string $name  The original name of the item that does not exist
  23.      * @param array  $items An array of possible items
  24.      */
  25.     public function addSuggestions(string $name, array $items): void
  26.     {
  27.         $alternatives = [];
  28.         foreach ($items as $item) {
  29.             $lev levenshtein($name$item);
  30.             if ($lev <= \strlen($name) / || false !== strpos($item$name)) {
  31.                 $alternatives[$item] = $lev;
  32.             }
  33.         }
  34.         if (!$alternatives) {
  35.             return;
  36.         }
  37.         asort($alternatives);
  38.         $this->appendMessage(sprintf(' Did you mean "%s"?'implode('", "'array_keys($alternatives))));
  39.     }
  40. }