Skip to content

Commit

Permalink
Fix access to optional array key when using debug_backtrace() function
Browse files Browse the repository at this point in the history
  • Loading branch information
ste93cry authored and sebastianbergmann committed Jan 14, 2022
1 parent 133d782 commit 6ac6234
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/Framework/Exception/InvalidArgumentException.php
Expand Up @@ -21,14 +21,18 @@ final class InvalidArgumentException extends Exception
{
public static function create(int $argument, string $type): self
{
$stack = debug_backtrace();
$stack = debug_backtrace();
$function = $stack[1]['function'];

if (isset($stack[1]['class'])) {
$function = sprintf('%s::%s', $stack[1]['class'], $stack[1]['function']);
}

return new self(
sprintf(
'Argument #%d of %s::%s() must be %s %s',
'Argument #%d of %s() must be %s %s',
$argument,
$stack[1]['class'],
$stack[1]['function'],
$function,
in_array(lcfirst($type)[0], ['a', 'e', 'i', 'o', 'u'], true) ? 'an' : 'a',
$type
)
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/TestResult.php
Expand Up @@ -738,8 +738,8 @@ function_exists('xdebug_start_function_monitor');
sprintf(
'%s in %s:%s',
$e->getMessage(),
$frame['file'],
$frame['line']
$frame['file'] ?? $e->getFile(),
$frame['line'] ?? $e->getLine()
)
);
} catch (Warning $e) {
Expand Down

0 comments on commit 6ac6234

Please sign in to comment.