Skip to content

Commit

Permalink
Merge pull request #1648 from ste93cry/fix-phpstan-access-to-undefine…
Browse files Browse the repository at this point in the history
…d-array-key

Fix access to optional array key when using `debug_backtrace()` function
  • Loading branch information
samsonasik committed Jan 8, 2022
2 parents 0af102a + 81b7411 commit 1f7170d
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 1f7170d

Please sign in to comment.