Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static callable. #2054

Merged
merged 1 commit into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/Twig/Node/Expression/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ private function getCallableParameters($callable, $isVariadic)
if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && array() === $argument->getDefaultValue()) {
array_pop($parameters);
} else {
$callableName = $r->name;
if ($r->getDeclaringClass()) {
$callableName = $r->getDeclaringClass()->name.'::'.$callableName;
}

throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".', $callableName, $this->getAttribute('type'), $this->getAttribute('name')));
throw new LogicException(sprintf(
'The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".',
$r instanceof ReflectionMethod ? $r->getDeclaringClass()->name.'::'.$r->name : $r->name,
$this->getAttribute('type'),
$this->getAttribute('name')
));
}
}

Expand Down
31 changes: 31 additions & 0 deletions test/Twig/Tests/Node/Expression/CallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ public function customFunction($arg1, $arg2 = 'default', $arg3 = array())
public function customFunctionWithArbitraryArguments()
{
}

/**
* @expectedException LogicException
* @expectedExceptionMessageRegExp #^The last parameter of "custom_Twig_Tests_Node_Expression_CallTest_function" for function "foo" must be an array with default value, eg\. "array \$arg \= array\(\)"\.$#
*/
public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnFunction()
{
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'foo', 'is_variadic' => true));
$node->getArguments('custom_Twig_Tests_Node_Expression_CallTest_function', array());
}

/**
* @expectedException LogicException
* @expectedExceptionMessageRegExp #^The last parameter of "CallableTestClass\:\:__invoke" for function "foo" must be an array with default value, eg\. "array \$arg \= array\(\)"\.$#
*/
public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnObject()
{
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'foo', 'is_variadic' => true));
$node->getArguments(new CallableTestClass(), array());
}
}

class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call
Expand All @@ -114,3 +134,14 @@ public function getArguments($callable, $arguments)
return parent::getArguments($callable, $arguments);
}
}

class CallableTestClass
{
public function __invoke($required)
{
}
}

function custom_Twig_Tests_Node_Expression_CallTest_function($required)
{
}