PluginProbe
WebTotem Security / 3.0.2
WebTotem Security v3.0.2
3.0.2 3.0.1 3.0.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.1 2.2.2 2.2.3 All 110 releases
wt-security / vendor / twig / twig / src / Error / SyntaxError.php

SyntaxError.php in WebTotem Security 3.0.2, at vendor/twig/twig/src/Error/SyntaxError.php

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