From 07cd08e0e46bbd007beeac3f41f033afe85cd5e7 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 28 Jun 2024 10:48:40 +0200 Subject: [PATCH] Fix CS --- src/Monolog/ErrorHandler.php | 4 +- src/Monolog/Formatter/HtmlFormatter.php | 2 +- src/Monolog/Formatter/LineFormatter.php | 5 ++- src/Monolog/Formatter/NormalizerFormatter.php | 2 +- src/Monolog/Formatter/SyslogFormatter.php | 1 - src/Monolog/Handler/AbstractHandler.php | 8 ++-- src/Monolog/Handler/AmqpHandler.php | 4 +- src/Monolog/Handler/BrowserConsoleHandler.php | 1 - src/Monolog/Handler/DeduplicationHandler.php | 8 ++-- src/Monolog/Handler/FilterHandler.php | 10 ++--- src/Monolog/Handler/FingersCrossedHandler.php | 8 ++-- src/Monolog/Handler/HandlerInterface.php | 2 +- src/Monolog/Handler/LogglyHandler.php | 5 +-- src/Monolog/Handler/NativeMailerHandler.php | 6 +-- src/Monolog/Handler/PushoverHandler.php | 8 ++-- src/Monolog/Handler/RotatingFileHandler.php | 4 +- src/Monolog/Handler/Slack/SlackRecord.php | 6 +-- src/Monolog/Handler/SlackHandler.php | 2 +- src/Monolog/Handler/SocketHandler.php | 2 +- src/Monolog/Handler/StreamHandler.php | 1 + src/Monolog/Handler/SymfonyMailerHandler.php | 6 +-- src/Monolog/Handler/SyslogHandler.php | 1 - src/Monolog/Level.php | 4 +- src/Monolog/Logger.php | 9 ++-- .../Processor/IntrospectionProcessor.php | 2 +- src/Monolog/Processor/TagProcessor.php | 4 +- .../Attribute/WithMonologChannelTest.php | 12 ++++- tests/Monolog/Formatter/JsonFormatterTest.php | 2 +- .../Formatter/NormalizerFormatterTest.php | 2 +- tests/Monolog/Handler/RedisHandlerTest.php | 15 +++++-- .../Handler/RotatingFileHandlerTest.php | 3 +- .../Handler/SymfonyMailerHandlerTest.php | 1 + tests/Monolog/LoggerTest.php | 45 +++++++++---------- tests/Monolog/PsrLogCompatTest.php | 2 +- 34 files changed, 106 insertions(+), 91 deletions(-) diff --git a/src/Monolog/ErrorHandler.php b/src/Monolog/ErrorHandler.php index d2ef247ea..452778b88 100644 --- a/src/Monolog/ErrorHandler.php +++ b/src/Monolog/ErrorHandler.php @@ -124,8 +124,8 @@ public function registerErrorHandler(array $levelMap = [], bool $callPrevious = } /** - * @param LogLevel::*|null $level a LogLevel::* constant, null to use the default LogLevel::ALERT - * @param int $reservedMemorySize Amount of KBs to reserve in memory so that it can be freed when handling fatal errors giving Monolog some room in memory to get its job done + * @param LogLevel::*|null $level a LogLevel::* constant, null to use the default LogLevel::ALERT + * @param int $reservedMemorySize Amount of KBs to reserve in memory so that it can be freed when handling fatal errors giving Monolog some room in memory to get its job done * @return $this */ public function registerFatalHandler($level = null, int $reservedMemorySize = 20): self diff --git a/src/Monolog/Formatter/HtmlFormatter.php b/src/Monolog/Formatter/HtmlFormatter.php index a2314ab55..b5d69bcfd 100644 --- a/src/Monolog/Formatter/HtmlFormatter.php +++ b/src/Monolog/Formatter/HtmlFormatter.php @@ -42,7 +42,7 @@ protected function getLevelColor(Level $level): string } /** - * @param string|null $dateFormat The format of the timestamp: one supported by DateTime::format + * @param string|null $dateFormat The format of the timestamp: one supported by DateTime::format * @throws \RuntimeException If the function json_encode does not exist */ public function __construct(?string $dateFormat = null) diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index 3ff840b7c..ba5852b39 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -84,7 +84,7 @@ public function includeStacktraces(bool $include = true, ?Closure $parser = null /** * Indent stack traces to separate them a bit from the main log record messages * - * @param string $indent The string used to indent, for example " " + * @param string $indent The string used to indent, for example " " * @return $this */ public function indentStacktraces(string $indent): self @@ -117,7 +117,7 @@ public function ignoreEmptyContextAndExtra(bool $ignore = true): self /** * Allows cutting the level name to get fixed-length levels like INF for INFO, ERR for ERROR if you set this to 3 for example * - * @param int|null $maxLevelNameLength Maximum characters for the level name. Set null for infinite length (default) + * @param int|null $maxLevelNameLength Maximum characters for the level name. Set null for infinite length (default) * @return $this */ public function setMaxLevelNameLength(?int $maxLevelNameLength = null): self @@ -244,6 +244,7 @@ protected function replaceNewlines(string $str): string $str = preg_replace('/(? */ private function formatExtra(LogRecord $record): array diff --git a/src/Monolog/Handler/AbstractHandler.php b/src/Monolog/Handler/AbstractHandler.php index d3c2cbd7b..61d45d58b 100644 --- a/src/Monolog/Handler/AbstractHandler.php +++ b/src/Monolog/Handler/AbstractHandler.php @@ -29,7 +29,7 @@ abstract class AbstractHandler extends Handler implements ResettableInterface /** * @param int|string|Level|LogLevel::* $level The minimum logging level at which this handler will be triggered - * @param bool $bubble Whether the messages that are handled can bubble up the stack or not + * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * * @phpstan-param value-of|value-of|Level|LogLevel::* $level */ @@ -50,7 +50,7 @@ public function isHandling(LogRecord $record): bool /** * Sets minimum logging level at which this handler will be triggered. * - * @param Level|LogLevel::* $level Level or level name + * @param Level|LogLevel::* $level Level or level name * @return $this * * @phpstan-param value-of|value-of|Level|LogLevel::* $level @@ -73,8 +73,8 @@ public function getLevel(): Level /** * Sets the bubbling behavior. * - * @param bool $bubble true means that this handler allows bubbling. - * false means that bubbling is not permitted. + * @param bool $bubble true means that this handler allows bubbling. + * false means that bubbling is not permitted. * @return $this */ public function setBubble(bool $bubble): self diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index 27d773ea4..119f33947 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -56,7 +56,7 @@ public function getExtraAttributes(): array /** * Configure extra attributes to pass to the AMQPExchange (if you are using the amqp extension) * - * @param array $extraAttributes One of content_type, content_encoding, + * @param array $extraAttributes One of content_type, content_encoding, * message_id, user_id, app_id, delivery_mode, * priority, timestamp, expiration, type * or reply_to, headers. @@ -65,6 +65,7 @@ public function getExtraAttributes(): array public function setExtraAttributes(array $extraAttributes): self { $this->extraAttributes = $extraAttributes; + return $this; } @@ -155,6 +156,7 @@ private function createAmqpMessage(string $data): AMQPMessage if (\count($this->extraAttributes) > 0) { $attributes = array_merge($attributes, $this->extraAttributes); } + return new AMQPMessage($data, $attributes); } diff --git a/src/Monolog/Handler/BrowserConsoleHandler.php b/src/Monolog/Handler/BrowserConsoleHandler.php index cbd158eaa..0d75cb313 100644 --- a/src/Monolog/Handler/BrowserConsoleHandler.php +++ b/src/Monolog/Handler/BrowserConsoleHandler.php @@ -17,7 +17,6 @@ use Monolog\LogRecord; use Monolog\Level; -use function count; use function headers_list; use function stripos; diff --git a/src/Monolog/Handler/DeduplicationHandler.php b/src/Monolog/Handler/DeduplicationHandler.php index c6e615c75..873a4b860 100644 --- a/src/Monolog/Handler/DeduplicationHandler.php +++ b/src/Monolog/Handler/DeduplicationHandler.php @@ -46,11 +46,11 @@ class DeduplicationHandler extends BufferHandler protected bool $gc = false; /** - * @param HandlerInterface $handler Handler. - * @param string|null $deduplicationStore The file/path where the deduplication log should be kept + * @param HandlerInterface $handler Handler. + * @param string|null $deduplicationStore The file/path where the deduplication log should be kept * @param int|string|Level|LogLevel::* $deduplicationLevel The minimum logging level for log records to be looked at for deduplication purposes - * @param int $time The period (in seconds) during which duplicate entries should be suppressed after a given log is sent through - * @param bool $bubble Whether the messages that are handled can bubble up the stack or not + * @param int $time The period (in seconds) during which duplicate entries should be suppressed after a given log is sent through + * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * * @phpstan-param value-of|value-of|Level|LogLevel::* $deduplicationLevel */ diff --git a/src/Monolog/Handler/FilterHandler.php b/src/Monolog/Handler/FilterHandler.php index 81dde3a16..6653fa15a 100644 --- a/src/Monolog/Handler/FilterHandler.php +++ b/src/Monolog/Handler/FilterHandler.php @@ -54,10 +54,10 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese /** * @phpstan-param (Closure(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler * - * @param Closure|HandlerInterface $handler Handler or factory Closure($record|null, $filterHandler). + * @param Closure|HandlerInterface $handler Handler or factory Closure($record|null, $filterHandler). * @param int|string|Level|array $minLevelOrList A list of levels to accept or a minimum level if maxLevel is provided - * @param int|string|Level|LogLevel::* $maxLevel Maximum level to accept, only used if $minLevelOrList is not an array - * @param bool $bubble Whether the messages that are handled can bubble up the stack or not + * @param int|string|Level|LogLevel::* $maxLevel Maximum level to accept, only used if $minLevelOrList is not an array + * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * * @phpstan-param value-of|value-of|Level|LogLevel::*|array|value-of|Level|LogLevel::*> $minLevelOrList * @phpstan-param value-of|value-of|Level|LogLevel::* $maxLevel @@ -78,8 +78,8 @@ public function getAcceptedLevels(): array } /** - * @param int|string|Level|LogLevel::*|array $minLevelOrList A list of levels to accept or a minimum level or level name if maxLevel is provided - * @param int|string|Level|LogLevel::* $maxLevel Maximum level or level name to accept, only used if $minLevelOrList is not an array + * @param int|string|Level|LogLevel::*|array $minLevelOrList A list of levels to accept or a minimum level or level name if maxLevel is provided + * @param int|string|Level|LogLevel::* $maxLevel Maximum level or level name to accept, only used if $minLevelOrList is not an array * @return $this * * @phpstan-param value-of|value-of|Level|LogLevel::*|array|value-of|Level|LogLevel::*> $minLevelOrList diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index 5c99d6ac3..76318307a 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -66,11 +66,11 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa /** * @phpstan-param (Closure(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler * - * @param Closure|HandlerInterface $handler Handler or factory Closure($record|null, $fingersCrossedHandler). + * @param Closure|HandlerInterface $handler Handler or factory Closure($record|null, $fingersCrossedHandler). * @param int|string|Level|LogLevel::* $activationStrategy Strategy which determines when this handler takes action, or a level name/value at which the handler is activated - * @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer. - * @param bool $bubble Whether the messages that are handled can bubble up the stack or not - * @param bool $stopBuffering Whether the handler should stop buffering after being triggered (default true) + * @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer. + * @param bool $bubble Whether the messages that are handled can bubble up the stack or not + * @param bool $stopBuffering Whether the handler should stop buffering after being triggered (default true) * @param int|string|Level|LogLevel::*|null $passthruLevel Minimum level to always flush to handler on close, even if strategy not triggered * * @phpstan-param value-of|value-of|Level|LogLevel::*|ActivationStrategyInterface $activationStrategy diff --git a/src/Monolog/Handler/HandlerInterface.php b/src/Monolog/Handler/HandlerInterface.php index 83905c323..93306d961 100644 --- a/src/Monolog/Handler/HandlerInterface.php +++ b/src/Monolog/Handler/HandlerInterface.php @@ -45,7 +45,7 @@ public function isHandling(LogRecord $record): bool; * * @param LogRecord $record The record to handle * @return bool true means that this handler handled the record, and that bubbling is not permitted. - * false means the record was either not processed or that this handler allows bubbling. + * false means the record was either not processed or that this handler allows bubbling. */ public function handle(LogRecord $record): bool; diff --git a/src/Monolog/Handler/LogglyHandler.php b/src/Monolog/Handler/LogglyHandler.php index 597e01179..ff298c661 100644 --- a/src/Monolog/Handler/LogglyHandler.php +++ b/src/Monolog/Handler/LogglyHandler.php @@ -14,7 +14,6 @@ use Monolog\Level; use Monolog\Formatter\FormatterInterface; use Monolog\Formatter\LogglyFormatter; -use function array_key_exists; use CurlHandle; use Monolog\LogRecord; @@ -88,7 +87,7 @@ private function loadCurlHandle(string $endpoint): CurlHandle } /** - * @param string[]|string $tag + * @param string[]|string $tag * @return $this */ public function setTag(string|array $tag): self @@ -103,7 +102,7 @@ public function setTag(string|array $tag): self } /** - * @param string[]|string $tag + * @param string[]|string $tag * @return $this */ public function addTag(string|array $tag): self diff --git a/src/Monolog/Handler/NativeMailerHandler.php b/src/Monolog/Handler/NativeMailerHandler.php index 70d6004e1..c68b1ddd0 100644 --- a/src/Monolog/Handler/NativeMailerHandler.php +++ b/src/Monolog/Handler/NativeMailerHandler.php @@ -78,7 +78,7 @@ public function __construct(string|array $to, string $subject, string $from, int /** * Add headers to the message * - * @param string|string[] $headers Custom added headers + * @param string|string[] $headers Custom added headers * @return $this */ public function addHeader($headers): self @@ -96,7 +96,7 @@ public function addHeader($headers): self /** * Add parameters to the message * - * @param string|string[] $parameters Custom added parameters + * @param string|string[] $parameters Custom added parameters * @return $this */ public function addParameter($parameters): self @@ -143,7 +143,7 @@ public function getEncoding(): string } /** - * @param string $contentType The content type of the email - Defaults to text/plain. Use text/html for HTML messages. + * @param string $contentType The content type of the email - Defaults to text/plain. Use text/html for HTML messages. * @return $this */ public function setContentType(string $contentType): self diff --git a/src/Monolog/Handler/PushoverHandler.php b/src/Monolog/Handler/PushoverHandler.php index f7389d1b9..b2a78955a 100644 --- a/src/Monolog/Handler/PushoverHandler.php +++ b/src/Monolog/Handler/PushoverHandler.php @@ -88,9 +88,9 @@ class PushoverHandler extends SocketHandler * to be retried for (every retry seconds). * * @param int|string|Level|LogLevel::* $highPriorityLevel The minimum logging level at which this handler will start - * sending "high priority" requests to the Pushover API + * sending "high priority" requests to the Pushover API * @param int|string|Level|LogLevel::* $emergencyLevel The minimum logging level at which this handler will start - * sending "emergency" requests to the Pushover API + * sending "emergency" requests to the Pushover API * * * @phpstan-param string|array $users @@ -207,7 +207,7 @@ protected function write(LogRecord $record): void } /** - * @param int|string|Level|LogLevel::* $level + * @param int|string|Level|LogLevel::* $level * @return $this * * @phpstan-param value-of|value-of|Level|LogLevel::* $level @@ -220,7 +220,7 @@ public function setHighPriorityLevel(int|string|Level $level): self } /** - * @param int|string|Level|LogLevel::* $level + * @param int|string|Level|LogLevel::* $level * @return $this * * @phpstan-param value-of|value-of|Level|LogLevel::* $level diff --git a/src/Monolog/Handler/RotatingFileHandler.php b/src/Monolog/Handler/RotatingFileHandler.php index da5521268..32a496b3b 100644 --- a/src/Monolog/Handler/RotatingFileHandler.php +++ b/src/Monolog/Handler/RotatingFileHandler.php @@ -182,8 +182,8 @@ protected function getGlobPattern(): string [$fileInfo['filename'], str_replace( ['Y', 'y', 'm', 'd'], ['[0-9][0-9][0-9][0-9]', '[0-9][0-9]', '[0-9][0-9]', '[0-9][0-9]'], - $this->dateFormat) - ], + $this->dateFormat + )], ($fileInfo['dirname'] ?? '') . '/' . $this->filenameFormat ); if (isset($fileInfo['extension'])) { diff --git a/src/Monolog/Handler/Slack/SlackRecord.php b/src/Monolog/Handler/Slack/SlackRecord.php index 99a7fe2a5..a10d6d6c8 100644 --- a/src/Monolog/Handler/Slack/SlackRecord.php +++ b/src/Monolog/Handler/Slack/SlackRecord.php @@ -220,7 +220,7 @@ public function stringify(array $fields): string /** * Channel used by the bot when posting * - * @param ?string $channel + * @param ?string $channel * @return $this */ public function setChannel(?string $channel = null): self @@ -233,7 +233,7 @@ public function setChannel(?string $channel = null): self /** * Username used by the bot when posting * - * @param ?string $username + * @param ?string $username * @return $this */ public function setUsername(?string $username = null): self @@ -292,7 +292,7 @@ public function includeContextAndExtra(bool $includeContextAndExtra = false): se } /** - * @param string[] $excludeFields + * @param string[] $excludeFields * @return $this */ public function excludeFields(array $excludeFields = []): self diff --git a/src/Monolog/Handler/SlackHandler.php b/src/Monolog/Handler/SlackHandler.php index c72d36208..2a34dda2d 100644 --- a/src/Monolog/Handler/SlackHandler.php +++ b/src/Monolog/Handler/SlackHandler.php @@ -255,7 +255,7 @@ public function includeContextAndExtra(bool $includeContextAndExtra): self } /** - * @param string[] $excludeFields + * @param string[] $excludeFields * @return $this */ public function excludeFields(array $excludeFields): self diff --git a/src/Monolog/Handler/SocketHandler.php b/src/Monolog/Handler/SocketHandler.php index 94e055f22..69a036f52 100644 --- a/src/Monolog/Handler/SocketHandler.php +++ b/src/Monolog/Handler/SocketHandler.php @@ -151,7 +151,7 @@ public function setTimeout(float $seconds): self /** * Set writing timeout. Only has effect during connection in the writing cycle. * - * @param float $seconds 0 for no timeout + * @param float $seconds 0 for no timeout * @return $this */ public function setWritingTimeout(float $seconds): self diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index 08cf85543..416909583 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -125,6 +125,7 @@ protected function write(LogRecord $record): void set_error_handler(function (...$args) { return $this->customErrorHandler(...$args); }); + try { $stream = fopen($url, 'a'); if ($this->filePermission !== null) { diff --git a/src/Monolog/Handler/SymfonyMailerHandler.php b/src/Monolog/Handler/SymfonyMailerHandler.php index 6e0fba341..33aa4fd7b 100644 --- a/src/Monolog/Handler/SymfonyMailerHandler.php +++ b/src/Monolog/Handler/SymfonyMailerHandler.php @@ -13,7 +13,6 @@ use Closure; use Monolog\Level; -use Monolog\Logger; use Monolog\LogRecord; use Monolog\Utils; use Monolog\Formatter\FormatterInterface; @@ -68,8 +67,8 @@ protected function getSubjectFormatter(?string $format): FormatterInterface /** * Creates instance of Email to be sent * - * @param string $content formatted email body to be sent - * @param LogRecord[] $records Log records that formed the content + * @param string $content formatted email body to be sent + * @param LogRecord[] $records Log records that formed the content */ protected function buildMessage(string $content, array $records): Email { @@ -82,6 +81,7 @@ protected function buildMessage(string $content, array $records): Email if (!$message instanceof Email) { $record = reset($records); + throw new \InvalidArgumentException('Could not resolve message as instance of Email or a callable returning it' . ($record instanceof LogRecord ? Utils::getRecordMessageForException($record) : '')); } diff --git a/src/Monolog/Handler/SyslogHandler.php b/src/Monolog/Handler/SyslogHandler.php index 99507a170..f3d7674c2 100644 --- a/src/Monolog/Handler/SyslogHandler.php +++ b/src/Monolog/Handler/SyslogHandler.php @@ -12,7 +12,6 @@ namespace Monolog\Handler; use Monolog\Level; -use Monolog\Utils; use Monolog\LogRecord; /** diff --git a/src/Monolog/Level.php b/src/Monolog/Level.php index 097d42135..5620bc4de 100644 --- a/src/Monolog/Level.php +++ b/src/Monolog/Level.php @@ -82,7 +82,7 @@ enum Level: int case Emergency = 600; /** - * @param value-of|LogLevel::*|'Debug'|'Info'|'Notice'|'Warning'|'Error'|'Critical'|'Alert'|'Emergency' $name + * @param value-of|LogLevel::*|'Debug'|'Info'|'Notice'|'Warning'|'Error'|'Critical'|'Alert'|'Emergency' $name * @return static */ public static function fromName(string $name): self @@ -100,7 +100,7 @@ public static function fromName(string $name): self } /** - * @param value-of $value + * @param value-of $value * @return static */ public static function fromValue(int $value): self diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index 0e3233816..edc62f3a8 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -230,7 +230,7 @@ public function popHandler(): HandlerInterface * * If a map is passed, keys will be ignored. * - * @param list $handlers + * @param list $handlers * @return $this */ public function setHandlers(array $handlers): self @@ -297,7 +297,7 @@ public function getProcessors(): array * by default. This function lets you disable them though in case you want * to suppress microseconds from the output. * - * @param bool $micro True to use microtime() to create timestamps + * @param bool $micro True to use microtime() to create timestamps * @return $this */ public function useMicrosecondTimestamps(bool $micro): self @@ -346,6 +346,7 @@ public function addRecord(int|Level $level, string $message, array $context = [] if ($logDepth === 3) { $this->warning('A possible infinite logging loop was detected and aborted. It appears some of your handler code is triggering logging, see the previous log record for a hint as to what may be the cause.'); + return false; } elseif ($logDepth >= 5) { // log depth 4 is let through, so we can log the warning above return false; @@ -470,8 +471,8 @@ public static function getLevelName(int|Level $level): string /** * Converts PSR-3 levels to Monolog ones if necessary * - * @param int|string|Level|LogLevel::* $level Level number (monolog) or name (PSR-3) - * @throws \Psr\Log\InvalidArgumentException If level is not defined + * @param int|string|Level|LogLevel::* $level Level number (monolog) or name (PSR-3) + * @throws \Psr\Log\InvalidArgumentException If level is not defined * * @phpstan-param value-of|value-of|Level|LogLevel::* $level */ diff --git a/src/Monolog/Processor/IntrospectionProcessor.php b/src/Monolog/Processor/IntrospectionProcessor.php index 433f4d28b..efc2f50aa 100644 --- a/src/Monolog/Processor/IntrospectionProcessor.php +++ b/src/Monolog/Processor/IntrospectionProcessor.php @@ -43,7 +43,7 @@ class IntrospectionProcessor implements ProcessorInterface /** * @param string|int|Level $level The minimum logging level at which this Processor will be triggered - * @param string[] $skipClassesPartials + * @param string[] $skipClassesPartials * * @phpstan-param value-of|value-of|Level|LogLevel::* $level */ diff --git a/src/Monolog/Processor/TagProcessor.php b/src/Monolog/Processor/TagProcessor.php index 10ed1cea3..f4e41ce20 100644 --- a/src/Monolog/Processor/TagProcessor.php +++ b/src/Monolog/Processor/TagProcessor.php @@ -32,7 +32,7 @@ public function __construct(array $tags = []) } /** - * @param string[] $tags + * @param string[] $tags * @return $this */ public function addTags(array $tags = []): self @@ -43,7 +43,7 @@ public function addTags(array $tags = []): self } /** - * @param string[] $tags + * @param string[] $tags * @return $this */ public function setTags(array $tags = []): self diff --git a/tests/Monolog/Attribute/WithMonologChannelTest.php b/tests/Monolog/Attribute/WithMonologChannelTest.php index 74875d7d0..9396e4b34 100644 --- a/tests/Monolog/Attribute/WithMonologChannelTest.php +++ b/tests/Monolog/Attribute/WithMonologChannelTest.php @@ -1,4 +1,13 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Monolog\Attribute; @@ -11,5 +20,4 @@ public function test(): void $attribute = new WithMonologChannel('fixture'); $this->assertSame('fixture', $attribute->channel); } - } diff --git a/tests/Monolog/Formatter/JsonFormatterTest.php b/tests/Monolog/Formatter/JsonFormatterTest.php index 76170018f..9ce91c696 100644 --- a/tests/Monolog/Formatter/JsonFormatterTest.php +++ b/tests/Monolog/Formatter/JsonFormatterTest.php @@ -121,7 +121,7 @@ public function testDefFormatWithException() public function testBasePathWithException(): void { $formatter = new JsonFormatter(); - $formatter->setBasePath(dirname(dirname(dirname(__DIR__)))); + $formatter->setBasePath(\dirname(\dirname(\dirname(__DIR__)))); $exception = new \RuntimeException('Foo'); $message = $this->formatRecordWithExceptionInContext($formatter, $exception); diff --git a/tests/Monolog/Formatter/NormalizerFormatterTest.php b/tests/Monolog/Formatter/NormalizerFormatterTest.php index 97aecefcd..d6dc3c5cf 100644 --- a/tests/Monolog/Formatter/NormalizerFormatterTest.php +++ b/tests/Monolog/Formatter/NormalizerFormatterTest.php @@ -84,7 +84,7 @@ public function testFormatExceptions() public function testFormatExceptionWithBasePath(): void { $formatter = new NormalizerFormatter('Y-m-d'); - $formatter->setBasePath(dirname(dirname(dirname(__DIR__)))); + $formatter->setBasePath(\dirname(\dirname(\dirname(__DIR__)))); $e = new \LogicException('bar'); $formatted = $formatter->normalizeValue([ 'exception' => $e, diff --git a/tests/Monolog/Handler/RedisHandlerTest.php b/tests/Monolog/Handler/RedisHandlerTest.php index dcb4aabdc..ec92fd1df 100644 --- a/tests/Monolog/Handler/RedisHandlerTest.php +++ b/tests/Monolog/Handler/RedisHandlerTest.php @@ -103,16 +103,25 @@ public function testPredisHandleCapped() { $redis = new class extends \Predis\Client { public array $testResults = []; - public function rpush(...$args) { + + public function rpush(...$args) + { $this->testResults[] = ['rpush', ...$args]; + return $this; } - public function ltrim(...$args) { + + public function ltrim(...$args) + { $this->testResults[] = ['ltrim', ...$args]; + return $this; } - public function transaction(...$args) { + + public function transaction(...$args) + { $this->testResults[] = ['transaction start']; + return ($args[0])($this); } }; diff --git a/tests/Monolog/Handler/RotatingFileHandlerTest.php b/tests/Monolog/Handler/RotatingFileHandlerTest.php index 8de357d96..3ada82ade 100644 --- a/tests/Monolog/Handler/RotatingFileHandlerTest.php +++ b/tests/Monolog/Handler/RotatingFileHandlerTest.php @@ -59,7 +59,8 @@ public function tearDown(): void unset($this->lastError); } - private function rrmdir($directory) { + private function rrmdir($directory) + { if (! is_dir($directory)) { throw new InvalidArgumentException("$directory must be a directory"); } diff --git a/tests/Monolog/Handler/SymfonyMailerHandlerTest.php b/tests/Monolog/Handler/SymfonyMailerHandlerTest.php index c9cf8835f..5e349ffa4 100644 --- a/tests/Monolog/Handler/SymfonyMailerHandlerTest.php +++ b/tests/Monolog/Handler/SymfonyMailerHandlerTest.php @@ -69,6 +69,7 @@ public function testMessageCanBeCustomizedGivenLoggedData() // Callback dynamically changes subject based on number of logged records $callback = function ($content, array $records) use ($expectedMessage) { $subject = \count($records) > 0 ? 'Emergency' : 'Normal'; + return $expectedMessage->subject($subject); }; $handler = new SymfonyMailerHandler($this->mailer, $callback); diff --git a/tests/Monolog/LoggerTest.php b/tests/Monolog/LoggerTest.php index 89d010ed4..9f78ccb91 100644 --- a/tests/Monolog/LoggerTest.php +++ b/tests/Monolog/LoggerTest.php @@ -285,11 +285,11 @@ public function testProcessorsAreCalledOnlyOnce() $handler->expects($this->any()) ->method('isHandling') ->willReturn(true); - ; + $handler->expects($this->any()) ->method('handle') ->willReturn(true); - ; + $logger->pushHandler($handler); $processor = $this->getMockBuilder('Monolog\Processor\WebProcessor') @@ -316,7 +316,7 @@ public function testProcessorsNotCalledWhenNotHandled() $handler->expects($this->once()) ->method('isHandling') ->willReturn(false); - ; + $logger->pushHandler($handler); $that = $this; $logger->pushProcessor(function ($record) use ($that) { @@ -337,29 +337,29 @@ public function testHandlersNotCalledBeforeFirstHandlingWhenProcessorsPresent() $handler1->expects($this->never()) ->method('isHandling') ->willReturn(false); - ; + $handler1->expects($this->once()) ->method('handle') ->willReturn(false); - ; + $logger->pushHandler($handler1); $handler2 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler2->expects($this->once()) ->method('isHandling') ->willReturn(true); - ; + $handler2->expects($this->once()) ->method('handle') ->willReturn(false); - ; + $logger->pushHandler($handler2); $handler3 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler3->expects($this->once()) ->method('isHandling') ->willReturn(false); - ; + $handler3->expects($this->never()) ->method('handle') ; @@ -377,27 +377,25 @@ public function testHandlersNotCalledBeforeFirstHandlingWhenProcessorsPresentWit $handler1->expects($this->never()) ->method('isHandling') ->willReturn(false); - ; + $handler1->expects($this->once()) ->method('handle') ->willReturn(false); - ; $handler2 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler2->expects($this->once()) ->method('isHandling') ->willReturn(true); - ; + $handler2->expects($this->once()) ->method('handle') ->willReturn(false); - ; $handler3 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler3->expects($this->once()) ->method('isHandling') ->willReturn(false); - ; + $handler3->expects($this->never()) ->method('handle') ; @@ -419,22 +417,22 @@ public function testBubblingWhenTheHandlerReturnsFalse() $handler1->expects($this->any()) ->method('isHandling') ->willReturn(true); - ; + $handler1->expects($this->once()) ->method('handle') ->willReturn(false); - ; + $logger->pushHandler($handler1); $handler2 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler2->expects($this->any()) ->method('isHandling') ->willReturn(true); - ; + $handler2->expects($this->once()) ->method('handle') ->willReturn(false); - ; + $logger->pushHandler($handler2); $logger->debug('test'); @@ -451,7 +449,7 @@ public function testNotBubblingWhenTheHandlerReturnsTrue() $handler1->expects($this->any()) ->method('isHandling') ->willReturn(true); - ; + $handler1->expects($this->never()) ->method('handle') ; @@ -461,11 +459,11 @@ public function testNotBubblingWhenTheHandlerReturnsTrue() $handler2->expects($this->any()) ->method('isHandling') ->willReturn(true); - ; + $handler2->expects($this->once()) ->method('handle') ->willReturn(true); - ; + $logger->pushHandler($handler2); $logger->debug('test'); @@ -482,7 +480,6 @@ public function testIsHandling() $handler1->expects($this->any()) ->method('isHandling') ->willReturn(false); - ; $logger->pushHandler($handler1); $this->assertFalse($logger->isHandling(Level::Debug)); @@ -491,7 +488,6 @@ public function testIsHandling() $handler2->expects($this->any()) ->method('isHandling') ->willReturn(true); - ; $logger->pushHandler($handler2); $this->assertTrue($logger->isHandling(Level::Debug)); @@ -677,7 +673,7 @@ public function testDefaultHandleException() $handler->expects($this->any()) ->method('isHandling') ->willReturn(true); - ; + $handler->expects($this->any()) ->method('handle') ->will($this->throwException(new \Exception('Some handler exception'))) @@ -706,7 +702,7 @@ public function testCustomHandleException() $handler->expects($this->any()) ->method('isHandling') ->willReturn(true); - ; + $handler->expects($this->any()) ->method('handle') ->will($this->throwException(new \Exception('Some handler exception'))) @@ -900,7 +896,6 @@ public function close(): void } } - class FiberSuspendHandler implements HandlerInterface { public function isHandling(LogRecord $record): bool diff --git a/tests/Monolog/PsrLogCompatTest.php b/tests/Monolog/PsrLogCompatTest.php index 1d51c55b5..ec7de22a8 100644 --- a/tests/Monolog/PsrLogCompatTest.php +++ b/tests/Monolog/PsrLogCompatTest.php @@ -161,7 +161,7 @@ public function testContextExceptionKeyCanBeExceptionOrOtherValues() /** * Creates a mock of a `Stringable`. * - * @param string $string The string that must be represented by the stringable. + * @param string $string The string that must be represented by the stringable. */ protected function createStringable(string $string = ''): MockObject&Stringable {