Skip to content

Commit 49ed71e

Browse files
ste93crysebastianbergmann
authored andcommitted
Fix access to optional array key when using debug_backtrace() function
1 parent 8c3b052 commit 49ed71e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Framework/Exception/InvalidArgumentException.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ final class InvalidArgumentException extends Exception
2121
{
2222
public static function create(int $argument, string $type): self
2323
{
24-
$stack = debug_backtrace();
24+
$stack = debug_backtrace();
25+
$function = $stack[1]['function'];
26+
27+
if (isset($stack[1]['class'])) {
28+
$function = sprintf('%s::%s', $stack[1]['class'], $stack[1]['function']);
29+
}
2530

2631
return new self(
2732
sprintf(
28-
'Argument #%d of %s::%s() must be %s %s',
33+
'Argument #%d of %s() must be %s %s',
2934
$argument,
30-
$stack[1]['class'],
31-
$stack[1]['function'],
35+
$function,
3236
in_array(lcfirst($type)[0], ['a', 'e', 'i', 'o', 'u'], true) ? 'an' : 'a',
3337
$type
3438
)

src/Framework/TestResult.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,8 @@ function_exists('xdebug_start_function_monitor');
755755
sprintf(
756756
'%s in %s:%s',
757757
$e->getMessage(),
758-
$frame['file'],
759-
$frame['line']
758+
$frame['file'] ?? $e->getFile(),
759+
$frame['line'] ?? $e->getLine()
760760
)
761761
);
762762
} catch (Warning $e) {

0 commit comments

Comments
 (0)