From 9dbcbe048245b0b6ee48b4333f13d7b9a0fe8fd7 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 28 Dec 2022 17:51:07 -0500 Subject: [PATCH 1/2] Remove extraneous Introspection->isTraceClassOrSkippedFunction second parameter --- src/Core/Logger/Util/Introspection.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Core/Logger/Util/Introspection.php b/src/Core/Logger/Util/Introspection.php index 987a4e3cb..bf1b77160 100644 --- a/src/Core/Logger/Util/Introspection.php +++ b/src/Core/Logger/Util/Introspection.php @@ -75,7 +75,7 @@ class Introspection implements IHaveCallIntrospections $i = 1; - while ($this->isTraceClassOrSkippedFunction($trace, $i)) { + while ($this->isTraceClassOrSkippedFunction($trace[$i] ?? [])) { $i++; } @@ -92,24 +92,23 @@ class Introspection implements IHaveCallIntrospections /** * Checks if the current trace class or function has to be skipped * - * @param array $trace The current trace array - * @param int $index The index of the current hierarchy level + * @param array $traceItem The current trace item * * @return bool True if the class or function should get skipped, otherwise false */ - private function isTraceClassOrSkippedFunction(array $trace, int $index): bool + private function isTraceClassOrSkippedFunction(array $traceItem): bool { - if (!isset($trace[$index])) { + if (!$traceItem) { return false; } - if (isset($trace[$index]['class'])) { + if (isset($traceItem['class'])) { foreach ($this->skipClassesPartials as $part) { - if (strpos($trace[$index]['class'], $part) !== false) { + if (strpos($traceItem['class'], $part) !== false) { return true; } } - } elseif (in_array($trace[$index]['function'], $this->skipFunctions)) { + } elseif (in_array($traceItem['function'], $this->skipFunctions)) { return true; } From 8b1947bd782549ed7e120c666dd7ee5499748503 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 28 Dec 2022 17:54:37 -0500 Subject: [PATCH 2/2] Add Core\Logger to the introspection skip class list - Make class list explicit to avoid confusion between similar class names - Update skipped class string match to a safer "starts with" condition --- src/Core/Logger/Capabilities/IHaveCallIntrospections.php | 7 +++---- src/Core/Logger/Util/Introspection.php | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Core/Logger/Capabilities/IHaveCallIntrospections.php b/src/Core/Logger/Capabilities/IHaveCallIntrospections.php index e9f27ee1a..a3ce90f1d 100644 --- a/src/Core/Logger/Capabilities/IHaveCallIntrospections.php +++ b/src/Core/Logger/Capabilities/IHaveCallIntrospections.php @@ -20,8 +20,6 @@ */ namespace Friendica\Core\Logger\Capabilities; -use Friendica\Core\Logger\Factory\Logger; -use Friendica\Util\Profiler; interface IHaveCallIntrospections { @@ -31,9 +29,10 @@ interface IHaveCallIntrospections * @var string[] */ public const IGNORE_CLASS_LIST = [ - Logger::class, - Profiler::class, + \Friendica\Core\Logger::class, + \Friendica\Core\Logger\Factory\Logger::class, 'Friendica\\Core\\Logger\\Type', + \Friendica\Util\Profiler::class, ]; /** diff --git a/src/Core/Logger/Util/Introspection.php b/src/Core/Logger/Util/Introspection.php index bf1b77160..2db30621e 100644 --- a/src/Core/Logger/Util/Introspection.php +++ b/src/Core/Logger/Util/Introspection.php @@ -104,7 +104,7 @@ class Introspection implements IHaveCallIntrospections if (isset($traceItem['class'])) { foreach ($this->skipClassesPartials as $part) { - if (strpos($traceItem['class'], $part) !== false) { + if (strpos($traceItem['class'], $part) === 0) { return true; } }