From 22663c4ae5d6dcb61d5a1ff151b711e5e0b337cc Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 29 Oct 2021 12:36:14 +0200 Subject: [PATCH] Move Introspection to Logger package --- src/Core/Logger/Factory/Logger.php | 2 +- src/Core/Logger/Type/AbstractLogger.php | 2 +- .../Type/Monolog/IntrospectionProcessor.php | 2 +- src/Core/Logger/Type/StreamLogger.php | 2 +- src/Core/Logger/Type/SyslogLogger.php | 2 +- src/{ => Core/Logger}/Util/Introspection.php | 19 +++++++++++-------- tests/src/Core/Logger/AbstractLoggerTest.php | 2 +- tests/src/Core/Logger/SyslogLoggerWrapper.php | 2 +- 8 files changed, 18 insertions(+), 15 deletions(-) rename src/{ => Core/Logger}/Util/Introspection.php (80%) diff --git a/src/Core/Logger/Factory/Logger.php b/src/Core/Logger/Factory/Logger.php index f9b32d9328..8f555483c8 100644 --- a/src/Core/Logger/Factory/Logger.php +++ b/src/Core/Logger/Factory/Logger.php @@ -27,7 +27,7 @@ use Friendica\Core; use Friendica\Core\Logger\Exception\LogLevelException; use Friendica\Database\Database; use Friendica\Util\FileSystem; -use Friendica\Util\Introspection; +use Friendica\Core\Logger\Util\Introspection; use Friendica\Core\Logger\Type\Monolog\DevelopHandler; use Friendica\Core\Logger\Type\Monolog\IntrospectionProcessor; use Friendica\Core\Logger\Type\ProfilerLogger; diff --git a/src/Core/Logger/Type/AbstractLogger.php b/src/Core/Logger/Type/AbstractLogger.php index 0b6d9f38fd..e26f1705d4 100644 --- a/src/Core/Logger/Type/AbstractLogger.php +++ b/src/Core/Logger/Type/AbstractLogger.php @@ -22,7 +22,7 @@ namespace Friendica\Core\Logger\Type; use Friendica\Core\Logger\Exception\LoggerException; -use Friendica\Util\Introspection; +use Friendica\Core\Logger\Util\Introspection; use Friendica\Util\Strings; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Core/Logger/Type/Monolog/IntrospectionProcessor.php b/src/Core/Logger/Type/Monolog/IntrospectionProcessor.php index 756331b22f..9da48ff36a 100644 --- a/src/Core/Logger/Type/Monolog/IntrospectionProcessor.php +++ b/src/Core/Logger/Type/Monolog/IntrospectionProcessor.php @@ -21,7 +21,7 @@ namespace Friendica\Core\Logger\Type\Monolog; -use Friendica\Util\Introspection; +use Friendica\Core\Logger\Util\Introspection; use Monolog\Logger; use Monolog\Processor\ProcessorInterface; diff --git a/src/Core/Logger/Type/StreamLogger.php b/src/Core/Logger/Type/StreamLogger.php index f67aef9a49..8d4d8b577e 100644 --- a/src/Core/Logger/Type/StreamLogger.php +++ b/src/Core/Logger/Type/StreamLogger.php @@ -26,7 +26,7 @@ use Friendica\Core\Logger\Exception\LoggerException; use Friendica\Core\Logger\Exception\LogLevelException; use Friendica\Util\DateTimeFormat; use Friendica\Util\FileSystem; -use Friendica\Util\Introspection; +use Friendica\Core\Logger\Util\Introspection; use Psr\Log\LogLevel; /** diff --git a/src/Core/Logger/Type/SyslogLogger.php b/src/Core/Logger/Type/SyslogLogger.php index 024d47b312..54cb327951 100644 --- a/src/Core/Logger/Type/SyslogLogger.php +++ b/src/Core/Logger/Type/SyslogLogger.php @@ -23,7 +23,7 @@ namespace Friendica\Core\Logger\Type; use Friendica\Core\Logger\Exception\LoggerException; use Friendica\Core\Logger\Exception\LogLevelException; -use Friendica\Util\Introspection; +use Friendica\Core\Logger\Util\Introspection; use Psr\Log\LogLevel; /** diff --git a/src/Util/Introspection.php b/src/Core/Logger/Util/Introspection.php similarity index 80% rename from src/Util/Introspection.php rename to src/Core/Logger/Util/Introspection.php index 540bfea728..7c2040bbf0 100644 --- a/src/Util/Introspection.php +++ b/src/Core/Logger/Util/Introspection.php @@ -19,15 +19,17 @@ * */ -namespace Friendica\Util; +namespace Friendica\Core\Logger\Util; /** * Get Introspection information about the current call */ class Introspection { + /** @var int */ private $skipStackFramesCount; + /** @var string[] */ private $skipClassesPartials; private $skipFunctions = [ @@ -36,10 +38,10 @@ class Introspection ]; /** - * @param array $skipClassesPartials An array of classes to skip during logging - * @param int $skipStackFramesCount If the logger should use information from other hierarchy levels of the call + * @param string[] $skipClassesPartials An array of classes to skip during logging + * @param int $skipStackFramesCount If the logger should use information from other hierarchy levels of the call */ - public function __construct($skipClassesPartials = array(), $skipStackFramesCount = 0) + public function __construct(array $skipClassesPartials = [], int $skipStackFramesCount = 0) { $this->skipClassesPartials = $skipClassesPartials; $this->skipStackFramesCount = $skipStackFramesCount; @@ -47,6 +49,7 @@ class Introspection /** * Adds new classes to get skipped + * * @param array $classNames */ public function addClasses(array $classNames) @@ -59,7 +62,7 @@ class Introspection * * @return array */ - public function getRecord() + public function getRecord(): array { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); @@ -73,8 +76,8 @@ class Introspection return [ 'file' => isset($trace[$i - 1]['file']) ? basename($trace[$i - 1]['file']) : null, - 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null, - 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null, + 'line' => $trace[$i - 1]['line'] ?? null, + 'function' => $trace[$i]['function'] ?? null, ]; } @@ -86,7 +89,7 @@ class Introspection * * @return bool True if the class or function should get skipped, otherwise false */ - private function isTraceClassOrSkippedFunction(array $trace, $index) + private function isTraceClassOrSkippedFunction(array $trace, int $index): bool { if (!isset($trace[$index])) { return false; diff --git a/tests/src/Core/Logger/AbstractLoggerTest.php b/tests/src/Core/Logger/AbstractLoggerTest.php index f1a0553102..2734158b5c 100644 --- a/tests/src/Core/Logger/AbstractLoggerTest.php +++ b/tests/src/Core/Logger/AbstractLoggerTest.php @@ -22,7 +22,7 @@ namespace Friendica\Test\src\Core\Logger; use Friendica\Test\MockedTest; -use Friendica\Util\Introspection; +use Friendica\Core\Logger\Util\Introspection; use Mockery\MockInterface; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/tests/src/Core/Logger/SyslogLoggerWrapper.php b/tests/src/Core/Logger/SyslogLoggerWrapper.php index 05dcbd6bc5..92d71f80a1 100644 --- a/tests/src/Core/Logger/SyslogLoggerWrapper.php +++ b/tests/src/Core/Logger/SyslogLoggerWrapper.php @@ -22,7 +22,7 @@ namespace Friendica\Test\src\Core\Logger; use Friendica\Core\Logger\Type\SyslogLogger; -use Friendica\Util\Introspection; +use Friendica\Core\Logger\Util\Introspection; use Psr\Log\LogLevel; /**