improve code style

This commit is contained in:
Daniel Seifert 2025-02-10 09:13:45 +01:00
parent 318b3739af
commit 6915e49ec3
4 changed files with 47 additions and 9 deletions

View File

@ -36,8 +36,15 @@ trait OxidLoggerTrait
}
/**
* @throws Exception
* @param string $loggerName
* @param string $filePath
* @param int $logLevel
* @param int|null $maxFiles
* @param array<int|string, string|array<string, string|int>> $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
);
}

View File

@ -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(

View File

@ -39,8 +39,15 @@ trait LoggerTrait
}
/**
* @throws Exception
* @param string $loggerName
* @param string $filePath
* @param int $logLevel
* @param int|null $maxFiles
* @param array<int|string, string|array<string, string|int>> $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);
}

View File

@ -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