if (!
$matches) { return null;
} $className =
$matches[1
];
$methodName =
$matches[2
];
$message =
sprintf('Attempted to call an undefined method named "%s" of class "%s".',
$methodName,
$className);
if ('' ===
$methodName || !
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 UndefinedMethodError($message,
$error);
} $candidates =
[];
foreach ($methods as $definedMethodName) { $lev =
levenshtein($methodName,
$definedMethodName);
if ($lev <= \
strlen($methodName) / 3 ||
str_contains($definedMethodName,
$methodName)) { $candidates[] =
$definedMethodName;
} } if ($candidates) {