function SyntaxError::addSuggestions
Tweaks the error message to include suggestions.
Parameters
string $name The original name of the item that does not exist:
array $items An array of possible items:
File
-
vendor/
twig/ twig/ src/ Error/ SyntaxError.php, line 28
Class
- SyntaxError
- \Exception thrown when a syntax error occurs during lexing or parsing of a template.
Namespace
Twig\ErrorCode
public function addSuggestions(string $name, array $items) : void {
$alternatives = [];
foreach ($items as $item) {
$lev = levenshtein($name, $item);
if ($lev <= \strlen($name) / 3 || str_contains($item, $name)) {
$alternatives[$item] = $lev;
}
}
if (!$alternatives) {
return;
}
asort($alternatives);
$this->appendMessage(\sprintf(' Did you mean "%s"?', implode('", "', array_keys($alternatives))));
}