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

Helpers: fixed suggestion when calling undefined method of anonymous … #248

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions src/Tracy/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ public static function improveException($e)
$message = "Call to undefined function $m[2](), did you mean $hint()?";

} elseif (preg_match('#^Call to undefined method (\S+)::(\w+)#', $message, $m)) {
$hint = self::getSuggestion(get_class_methods($m[1]), $m[2]);
$message .= ", did you mean $hint()?";
if ($m[1] !== 'class@anonymous') {
$hint = self::getSuggestion(get_class_methods($m[1]), $m[2]);
$message .= ", did you mean $hint()?";
}

} elseif (preg_match('#^Undefined variable: (\w+)#', $message, $m) && !empty($e->context)) {
$hint = self::getSuggestion(array_keys($e->context), $m[1]);
Expand Down
10 changes: 10 additions & 0 deletions tests/Tracy/Helpers.improveException.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ test(function () use ($obj) { // suggest only public method
Assert::same('Call to undefined method TestClass::protectedMethodX()', $e->getMessage());
});

test(function () { // do not suggest anything when accessing anonymous class
try {
$obj = new class {};

$obj->publicMethodOnAnonymousClass();
} catch (\Error $e) {}
Helpers::improveException($e);
Assert::same('Call to undefined method class@anonymous::publicMethodOnAnonymousClass()', $e->getMessage());
});


// reading
test(function () use ($obj) {
Expand Down