From f8522f3bf3ec53ef570c592cc0327e20cefae2c1 Mon Sep 17 00:00:00 2001 From: Thomas Nordahl Pedersen Date: Tue, 13 Sep 2022 12:59:26 +0200 Subject: [PATCH] Small refactor in ExceptionReporter to avoid error suppression operator (#7) * Temporarily added PHP 7.4 to Travis * Set up Codeception * Ported tests from mindplay/testies to Codeception 5. Also adjusted tests breaking on PHP 7.4+ * Updated composer.lock * Changed travis versions to 8.0 and 8.1 * Removed legacy flag from composer command. Changed PHP requirements in composer.json to >=8.0 and removed phpbrowser package * Removing composer.lock to avoid locking symfony packages at php >=8.1 * Small refactor in ExceptionReporter to avoid error suppression operator Co-authored-by: Hans Erik Jepsen --- src/Extensions/ExceptionReporter.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Extensions/ExceptionReporter.php b/src/Extensions/ExceptionReporter.php index e15e19d..bc4a291 100644 --- a/src/Extensions/ExceptionReporter.php +++ b/src/Extensions/ExceptionReporter.php @@ -162,7 +162,7 @@ protected function createStackTrace(array $trace): StackTrace { $frames = []; - foreach ($trace as $index => $entry) { + foreach ($trace as $entry) { $frames[] = $this->createStackFrame($entry); } @@ -178,13 +178,9 @@ protected function createStackTrace(array $trace): StackTrace */ protected function createStackFrame(array $entry): StackFrame { - $filename = isset($entry["file"]) - ? $entry["file"] - : self::NO_FILE; + $filename = $entry["file"] ?? self::NO_FILE; - $function = isset($entry["class"]) - ? $entry["class"] . @$entry["type"] . @$entry["function"] - : @$entry["function"]; + $function = $this->getFunctionFromEntry($entry); $lineno = array_key_exists("line", $entry) ? (int) $entry["line"] @@ -430,4 +426,17 @@ protected function formatValue($value): string return "{{$type}}"; // "unknown type" and possibly unsupported (future) types } + + private function getFunctionFromEntry(array $entry) + { + $function = $entry["function"] ?? ""; + $class = $entry["class"] ?? ""; + $type = $entry["type"] ?? ""; + + if ($class !== "") { + return $class . $type . $function; + } else { + return $function; + } + } }