From 6915e49ec340550dfaf9cae4cc31f8d6b0bae8fd Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Mon, 10 Feb 2025 09:13:45 +0100 Subject: [PATCH] improve code style --- src/Apps/OxidLoggerTrait.php | 13 ++++++++++--- src/GuzzleFactory.php | 1 + src/LoggerTrait.php | 16 +++++++++++----- tests/LoggerTestTrait.php | 26 +++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/Apps/OxidLoggerTrait.php b/src/Apps/OxidLoggerTrait.php index 94b6b25..9475eda 100644 --- a/src/Apps/OxidLoggerTrait.php +++ b/src/Apps/OxidLoggerTrait.php @@ -36,8 +36,15 @@ trait OxidLoggerTrait } /** - * @throws Exception + * @param string $loggerName + * @param string $filePath + * @param int $logLevel + * @param int|null $maxFiles + * @param array> $specialHandlers + * + * @return void * @throws InvalidArgumentException + * @throws Exception */ public function addCombinedOxidAndFileLogger( string $loggerName, @@ -45,8 +52,7 @@ trait OxidLoggerTrait int $logLevel = Logger::INFO, ?int $maxFiles = null, array $specialHandlers = [] - ): void - { + ): void { if (isset($this->loggers['oxid'])) { unset($this->loggers['oxid']); } @@ -56,6 +62,7 @@ trait OxidLoggerTrait $filePath, $logLevel, $maxFiles, + /** @phpstan-ignore argument.type */ $specialHandlers ); } diff --git a/src/GuzzleFactory.php b/src/GuzzleFactory.php index 4aaad44..4ad3f12 100644 --- a/src/GuzzleFactory.php +++ b/src/GuzzleFactory.php @@ -52,6 +52,7 @@ class GuzzleFactory foreach ($this->getLoggers() as $logger) { /** @var 'alert'|'critical'|'debug'|'emergency'|'error'|'info'|'notice'|'warning' $logLevelName */ + /** @phpstan-ignore argument.type */ $logLevelName = Logger::getLevelName($this->getMessageLevel()); $stack->push( Middleware::log( diff --git a/src/LoggerTrait.php b/src/LoggerTrait.php index 42d68ea..011e09b 100644 --- a/src/LoggerTrait.php +++ b/src/LoggerTrait.php @@ -39,8 +39,15 @@ trait LoggerTrait } /** - * @throws Exception + * @param string $loggerName + * @param string $filePath + * @param int $logLevel + * @param int|null $maxFiles + * @param array> $specialHandlers + * + * @return void * @throws InvalidArgumentException + * @throws Exception */ public function addFileLogger( string $loggerName, @@ -48,9 +55,9 @@ trait LoggerTrait int $logLevel = Logger::INFO, ?int $maxFiles = null, array $specialHandlers = [] // see LoggerFactory constants - ): void - { + ): void { $this->loggers[$loggerName] = $this->getLoggerFactory() + /** @phpstan-ignore argument.type */ ->getFileLogger($loggerName, $filePath, $logLevel, $maxFiles, $specialHandlers); } @@ -66,8 +73,7 @@ trait LoggerTrait string $filePath, int $logLevel = Logger::INFO, ?int $maxFiles = null - ): AbstractProcessingHandler - { + ): AbstractProcessingHandler { return $this->getLoggerFactory()->getFileLoggerStreamHandler($filePath, $logLevel, $maxFiles); } diff --git a/tests/LoggerTestTrait.php b/tests/LoggerTestTrait.php index c2ced5b..789c60a 100644 --- a/tests/LoggerTestTrait.php +++ b/tests/LoggerTestTrait.php @@ -18,7 +18,6 @@ namespace D3\GuzzleFactory\tests; use D3\GuzzleFactory\GuzzleFactory; use D3\LoggerFactory\LoggerFactory; use Generator; -use Monolog\Handler\AbstractProcessingHandler; use Monolog\Handler\StreamHandler; use Monolog\Logger; use ReflectionException; @@ -82,6 +81,31 @@ trait LoggerTestTrait yield [Logger::INFO, null]; } + /** + * @test + * @return void + * @throws ReflectionException + * @covers \D3\GuzzleFactory\GuzzleFactory::getFileLoggerStreamHandler + */ + public function testGetFileLoggerStreamHandler(): void + { + $loggerFactory = $this->getMockBuilder(LoggerFactory::class) + ->onlyMethods(['getFileLoggerStreamHandler']) + ->getMock(); + $loggerFactory->expects($this->once())->method('getFileLoggerStreamHandler'); + + $sut = $this->getMockBuilder(GuzzleFactory::class) + ->onlyMethods(['getLoggerFactory']) + ->getMock(); + $sut->method("getLoggerFactory")->willReturn($loggerFactory); + + $this->callMethod( + $sut, + 'getFileLoggerStreamHandler', + ['file/path.log', Logger::ERROR, 2] + ); + } + /** * @test * @return void