diff options
| author | wn_ <invalid@email.com> | 2024-11-12 03:15:53 +0000 |
|---|---|---|
| committer | wn_ <invalid@email.com> | 2024-11-12 03:15:53 +0000 |
| commit | a784305cc764a7e039ad87074f541db68a653a5a (patch) | |
| tree | 508c428e11d5559c3c25ad01ffe1ba474f7da270 /include/errorhandler.php | |
| parent | e4c57769e005e75b80ec0fa206fed8ff69e58162 (diff) | |
Address PHPStan findings as of 2.0.1
Diffstat (limited to 'include/errorhandler.php')
| -rw-r--r-- | include/errorhandler.php | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/include/errorhandler.php b/include/errorhandler.php index ea464f77a..4f773bc19 100644 --- a/include/errorhandler.php +++ b/include/errorhandler.php @@ -2,40 +2,38 @@ /** * @param array<int, array<string, mixed>> $trace */ -function format_backtrace($trace): string { +function format_backtrace(array $trace): string { $rv = ""; $idx = 1; - if (is_array($trace)) { - foreach ($trace as $e) { - if (isset($e["file"]) && isset($e["line"])) { - $fmt_args = []; - - if (is_array($e["args"] ?? false)) { - foreach ($e["args"] as $a) { - if (is_object($a)) { - array_push($fmt_args, "{" . get_class($a) . "}"); - } else if (is_array($a)) { - array_push($fmt_args, "[" . truncate_string(json_encode($a), 256, "...")) . "]"; - } else if (is_resource($a)) { - array_push($fmt_args, truncate_string(get_resource_type($a), 256, "...")); - } else if (is_string($a)) { - array_push($fmt_args, truncate_string($a, 256, "...")); - } + foreach ($trace as $e) { + if (isset($e["file"]) && isset($e["line"])) { + $fmt_args = []; + + if (is_array($e["args"] ?? false)) { + foreach ($e["args"] as $a) { + if (is_object($a)) { + array_push($fmt_args, "{" . get_class($a) . "}"); + } else if (is_array($a)) { + array_push($fmt_args, "[" . truncate_string(json_encode($a), 256, "...")) . "]"; + } else if (is_resource($a)) { + array_push($fmt_args, truncate_string(get_resource_type($a), 256, "...")); + } else if (is_string($a)) { + array_push($fmt_args, truncate_string($a, 256, "...")); } } + } - $filename = str_replace(dirname(__DIR__) . "/", "", $e["file"]); + $filename = str_replace(dirname(__DIR__) . "/", "", $e["file"]); - $rv .= sprintf("%d. %s(%s): %s(%s)\n", - $idx, - $filename, - $e["line"], - $e["function"], - implode(", ", $fmt_args)); + $rv .= sprintf("%d. %s(%s): %s(%s)\n", + $idx, + $filename, + $e["line"], + $e["function"], + implode(", ", $fmt_args)); - $idx++; - } + $idx++; } } |