[Debug] UndefinedMethodFatalErrorHandler - Handle anonymous classes
This commit is contained in:
parent
948b44c461
commit
ed713aef2b
@ -36,8 +36,13 @@ class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface
|
|||||||
|
|
||||||
$message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className);
|
$message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className);
|
||||||
|
|
||||||
|
if (!class_exists($className) || null === $methods = get_class_methods($className)) {
|
||||||
|
// failed to get the class or its methods on which an unknown method was called (for example on an anonymous class)
|
||||||
|
return new UndefinedMethodException($message, $exception);
|
||||||
|
}
|
||||||
|
|
||||||
$candidates = array();
|
$candidates = array();
|
||||||
foreach (get_class_methods($className) as $definedMethodName) {
|
foreach ($methods as $definedMethodName) {
|
||||||
$lev = levenshtein($methodName, $definedMethodName);
|
$lev = levenshtein($methodName, $definedMethodName);
|
||||||
if ($lev <= strlen($methodName) / 3 || false !== strpos($definedMethodName, $methodName)) {
|
if ($lev <= strlen($methodName) / 3 || false !== strpos($definedMethodName, $methodName)) {
|
||||||
$candidates[] = $definedMethodName;
|
$candidates[] = $definedMethodName;
|
||||||
@ -52,6 +57,7 @@ class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface
|
|||||||
} else {
|
} else {
|
||||||
$candidates = '"'.$last;
|
$candidates = '"'.$last;
|
||||||
}
|
}
|
||||||
|
|
||||||
$message .= "\nDid you mean to call ".$candidates;
|
$message .= "\nDid you mean to call ".$candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,15 @@ class UndefinedMethodFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
),
|
),
|
||||||
"Attempted to call an undefined method named \"offsetFet\" of class \"SplObjectStorage\".\nDid you mean to call e.g. \"offsetGet\", \"offsetSet\" or \"offsetUnset\"?",
|
"Attempted to call an undefined method named \"offsetFet\" of class \"SplObjectStorage\".\nDid you mean to call e.g. \"offsetGet\", \"offsetSet\" or \"offsetUnset\"?",
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'type' => 1,
|
||||||
|
'message' => 'Call to undefined method class@anonymous::test()',
|
||||||
|
'file' => '/home/possum/work/symfony/test.php',
|
||||||
|
'line' => 11,
|
||||||
|
),
|
||||||
|
'Attempted to call an undefined method named "test" of class "class@anonymous".',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user