From afa7da65b199250badaacaa3fd4d95b5e48ff9db Mon Sep 17 00:00:00 2001 From: Peter Csajtai Date: Fri, 23 Aug 2024 11:05:48 +0200 Subject: [PATCH] Fix errors reported by phpstan --- src/Log/DefaultLogger.php | 19 ++++++++++--------- src/Log/InternalLogger.php | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Log/DefaultLogger.php b/src/Log/DefaultLogger.php index 44f30f4..d84059c 100644 --- a/src/Log/DefaultLogger.php +++ b/src/Log/DefaultLogger.php @@ -11,47 +11,48 @@ class DefaultLogger implements LoggerInterface { - public function emergency($message, array $context = []): void + public function emergency(string|Stringable $message, array $context = []): void { self::logMsg(LogLevel::EMERGENCY, $message, $context); } - public function alert($message, array $context = []): void + public function alert(string|Stringable $message, array $context = []): void { self::logMsg(LogLevel::ALERT, $message, $context); } - public function critical($message, array $context = []): void + public function critical(string|Stringable $message, array $context = []): void { self::logMsg(LogLevel::CRITICAL, $message, $context); } - public function error($message, array $context = []): void + public function error(string|Stringable $message, array $context = []): void { self::logMsg(LogLevel::ERROR, $message, $context); } - public function warning($message, array $context = []): void + public function warning(string|Stringable $message, array $context = []): void { self::logMsg(LogLevel::WARNING, $message, $context); } - public function notice($message, array $context = []): void + public function notice(string|Stringable $message, array $context = []): void { self::logMsg(LogLevel::NOTICE, $message, $context); } - public function info($message, array $context = []): void + public function info(string|Stringable $message, array $context = []): void { self::logMsg(LogLevel::INFO, $message, $context); } - public function debug($message, array $context = []): void + public function debug(string|Stringable $message, array $context = []): void { self::logMsg(LogLevel::DEBUG, $message, $context); } - public function log($level, $message, array $context = []): void + /** @phpstan-ignore-next-line */ + public function log($level, string|Stringable $message, array $context = []): void { // Do nothing, only the leveled methods should be used. } diff --git a/src/Log/InternalLogger.php b/src/Log/InternalLogger.php index c2bf963..f5b3d6d 100644 --- a/src/Log/InternalLogger.php +++ b/src/Log/InternalLogger.php @@ -26,7 +26,7 @@ public function __construct( private readonly Hooks $hooks ) {} - public function emergency($message, array $context = []): void + public function emergency(string|Stringable $message, array $context = []): void { $this->hooks->fireOnError(self::format($message, $context), $context['exception'] ?? null); if ($this->shouldLog(LogLevel::EMERGENCY, $context)) { @@ -35,7 +35,7 @@ public function emergency($message, array $context = []): void } } - public function alert($message, array $context = []): void + public function alert(string|Stringable $message, array $context = []): void { $this->hooks->fireOnError(self::format($message, $context), $context['exception'] ?? null); if ($this->shouldLog(LogLevel::ALERT, $context)) { @@ -44,7 +44,7 @@ public function alert($message, array $context = []): void } } - public function critical($message, array $context = []): void + public function critical(string|Stringable $message, array $context = []): void { $this->hooks->fireOnError(self::format($message, $context), $context['exception'] ?? null); if ($this->shouldLog(LogLevel::CRITICAL, $context)) { @@ -53,7 +53,7 @@ public function critical($message, array $context = []): void } } - public function error($message, array $context = []): void + public function error(string|Stringable $message, array $context = []): void { $this->hooks->fireOnError(self::format($message, $context), $context['exception'] ?? null); if ($this->shouldLog(LogLevel::ERROR, $context)) { @@ -62,7 +62,7 @@ public function error($message, array $context = []): void } } - public function warning($message, array $context = []): void + public function warning(string|Stringable $message, array $context = []): void { if ($this->shouldLog(LogLevel::WARNING, $context)) { $enriched = $this->enrichMessage($message, $context); @@ -70,7 +70,7 @@ public function warning($message, array $context = []): void } } - public function notice($message, array $context = []): void + public function notice(string|Stringable $message, array $context = []): void { if ($this->shouldLog(LogLevel::NOTICE, $context)) { $enriched = $this->enrichMessage($message, $context); @@ -78,7 +78,7 @@ public function notice($message, array $context = []): void } } - public function info($message, array $context = []): void + public function info(string|Stringable $message, array $context = []): void { if ($this->shouldLog(LogLevel::INFO, $context)) { $enriched = $this->enrichMessage($message, $context); @@ -86,7 +86,7 @@ public function info($message, array $context = []): void } } - public function debug($message, array $context = []): void + public function debug(string|Stringable $message, array $context = []): void { if ($this->shouldLog(LogLevel::DEBUG, $context)) { $enriched = $this->enrichMessage($message, $context); @@ -94,7 +94,8 @@ public function debug($message, array $context = []): void } } - public function log($level, $message, array $context = []): void + /** @phpstan-ignore-next-line */ + public function log($level, string|Stringable $message, array $context = []): void { // Do nothing, only the leveled methods should be used. }