From a784305cc764a7e039ad87074f541db68a653a5a Mon Sep 17 00:00:00 2001 From: wn_ Date: Tue, 12 Nov 2024 03:15:53 +0000 Subject: Address PHPStan findings as of 2.0.1 --- include/errorhandler.php | 50 +++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'include/errorhandler.php') 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> $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++; } } -- cgit v1.2.3-54-g00ecf