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 committed Jan 7, 2022
1 parent e33afe6 commit 81b7411
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Exception/ShouldNotHappenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ private function createDefaultMessageWithLocation(): string
{
$debugBacktrace = debug_backtrace();

$class = $debugBacktrace[2]['class'] ?? null;
$function = (string) $debugBacktrace[2]['function'];
$line = (int) $debugBacktrace[1]['line'];
$class = isset($debugBacktrace[2]['class']) ? (string) $debugBacktrace[2]['class'] : null;
$function = isset($debugBacktrace[2]['function']) ? (string) $debugBacktrace[2]['function'] : '';
$line = isset($debugBacktrace[1]['line']) ? (int) $debugBacktrace[1]['line'] : 0;

$method = $class ? ($class . '::' . $function) : $function;
$method = $class !== null ? ($class . '::' . $function) : $function;

return sprintf('Look at "%s()" on line %d', $method, $line);
}
Expand Down

0 comments on commit 81b7411

Please sign in to comment.