Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Help the developer when they specify an invalid function by providing…

… some alternatives
  • Loading branch information...
commit 2c79f494f5772bfaeea5663a04ae52a48d1e6182 1 parent 55c7ff0
@jonathaningram jonathaningram authored committed
Showing with 19 additions and 2 deletions.
  1. +19 −2 lib/Twig/Node/Expression/Function.php
View
21 lib/Twig/Node/Expression/Function.php
@@ -17,9 +17,26 @@ public function __construct($name, Twig_NodeInterface $arguments, $lineno)
public function compile(Twig_Compiler $compiler)
{
- $function = $compiler->getEnvironment()->getFunction($this->getAttribute('name'));
+ $name = $this->getAttribute('name');
+
+ $function = $compiler->getEnvironment()->getFunction($name);
+
if (false === $function) {
- throw new Twig_Error_Syntax(sprintf('The function "%s" does not exist', $this->getAttribute('name')), $this->getLine());
+ $alternativeFunctions = array();
+
+ foreach ($compiler->getEnvironment()->getFunctions() as $functionName => $function) {
+ if (false !== strpos($functionName, $name)) {
+ $alternativeFunctions[] = $functionName;
+ }
+ }
+
+ $exceptionMessage = sprintf('The function "%s" does not exist', $name);
+
+ if (count($alternativeFunctions)) {
+ $exceptionMessage = sprintf('%s. Did you mean "%s"?', $exceptionMessage, implode('", "', $alternativeFunctions));
+ }
+
+ throw new Twig_Error_Syntax($exceptionMessage, $this->getLine());
}
$compiler
Please sign in to comment.
Something went wrong with that request. Please try again.