From 80eeb8caf26308240fc49ef55569a3a10d6e287e Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Tue, 7 Feb 2023 10:39:54 +0300 Subject: [PATCH] Add rector + fix psalm (#87) * Add rector files https://github.com/yiisoft/yii-dev-tool/pull/232 * Add rector/rector dependecy * [rector] Apply fixes * Apply fixes from StyleCI * Use predefined rector action * fix * fix psalm --------- Co-authored-by: rector-bot Co-authored-by: StyleCI Bot Co-authored-by: Sergei Predvoditelev --- .github/workflows/rector.yml | 21 +++++++++++ composer.json | 1 + psalm.xml | 3 +- rector.php | 27 ++++++++++++++ src/Logger.php | 18 +++------ src/Message/CategoryFilter.php | 3 +- src/PsrTarget.php | 10 +---- src/StreamTarget.php | 11 +----- tests/LoggerTest.php | 21 ++--------- tests/Message/CategoryFilterTest.php | 4 -- tests/Message/FormatterTest.php | 34 ++++++----------- tests/MessageTest.php | 6 --- tests/PsrTargetTest.php | 8 +--- tests/StreamTargetTest.php | 5 --- tests/TargetTest.php | 56 +++++----------------------- 15 files changed, 88 insertions(+), 140 deletions(-) create mode 100644 .github/workflows/rector.yml create mode 100644 rector.php diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml new file mode 100644 index 000000000..adacd735a --- /dev/null +++ b/.github/workflows/rector.yml @@ -0,0 +1,21 @@ +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' + +name: rector + +jobs: + rector: + uses: yiisoft/actions/.github/workflows/rector.yml@master + with: + os: >- + ['ubuntu-latest'] + php: >- + ['8.0'] diff --git a/composer.json b/composer.json index a576b03ee..6687e21e2 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "require-dev": { "maglnet/composer-require-checker": "^4.4", "phpunit/phpunit": "^9.5", + "rector/rector": "^0.15.13", "roave/infection-static-analysis-plugin": "^1.18", "spatie/phpunit-watcher": "^1.23", "vimeo/psalm": "^4.22" diff --git a/psalm.xml b/psalm.xml index deb39dc13..2f9469cb8 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,8 @@ paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + // register a single rule + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + + // define sets of rules + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_80, + ]); + + $rectorConfig->skip([ + ClosureToArrowFunctionRector::class, + ]); +}; diff --git a/src/Logger.php b/src/Logger.php index 5612736fc..fdd1424ba 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -16,7 +16,6 @@ use function count; use function debug_backtrace; use function gettype; -use function get_class; use function implode; use function in_array; use function is_string; @@ -148,8 +147,6 @@ public function getTargets(): array /** * @param string $level - * @param string|Stringable $message - * @param array $context * @psalm-param LogMessageContext $context * @psalm-suppress MoreSpecificImplementedParamType */ @@ -187,8 +184,6 @@ public function flush(bool $final = false): void * * @param int $flushInterval The number of messages to accumulate before flushing. * - * @return self - * * @see Logger::$flushInterval */ public function setFlushInterval(int $flushInterval): self @@ -202,8 +197,6 @@ public function setFlushInterval(int $flushInterval): self * * @param int $traceLevel The number of call stack information. * - * @return self - * * @see Logger::$traceLevel */ public function setTraceLevel(int $traceLevel): self @@ -219,8 +212,6 @@ public function setTraceLevel(int $traceLevel): self * * @throws InvalidArgumentException for non-string values. * - * @return self - * * @see Logger::$excludedTracePaths */ public function setExcludedTracePaths(array $excludedTracePaths): self @@ -276,7 +267,7 @@ private function dispatch(array $messages, bool $final): void $target->disable(); $targetErrors[] = new Message( LogLevel::WARNING, - 'Unable to send log via ' . get_class($target) . ': ' . get_class($e) . ': ' . $e->getMessage(), + 'Unable to send log via ' . $target::class . ': ' . $e::class . ': ' . $e->getMessage(), ['time' => microtime(true), 'exception' => $e], ); } @@ -306,9 +297,10 @@ private function collectTrace(array $backtrace): array foreach ($backtrace as $trace) { if (isset($trace['file'], $trace['line'])) { - $excludedMatch = array_filter($this->excludedTracePaths, static function ($path) use ($trace) { - return str_contains($trace['file'], $path); - }); + $excludedMatch = array_filter( + $this->excludedTracePaths, + static fn ($path) => str_contains($trace['file'], $path) + ); if (empty($excludedMatch)) { unset($trace['object'], $trace['args']); diff --git a/src/Message/CategoryFilter.php b/src/Message/CategoryFilter.php index 4e3c15aa3..5b38d3a0c 100644 --- a/src/Message/CategoryFilter.php +++ b/src/Message/CategoryFilter.php @@ -9,7 +9,6 @@ use function gettype; use function is_string; use function rtrim; -use function substr_compare; use function sprintf; /** @@ -95,7 +94,7 @@ public function isExcluded(string $category): bool $category === $include || ( !empty($include) - && substr_compare($include, '*', -1, 1) === 0 + && str_ends_with($include, '*') && str_starts_with($category, rtrim($include, '*')) ) ) { diff --git a/src/PsrTarget.php b/src/PsrTarget.php index 58dcc36f1..486aff1eb 100644 --- a/src/PsrTarget.php +++ b/src/PsrTarget.php @@ -11,19 +11,13 @@ */ final class PsrTarget extends Target { - /** - * @var LoggerInterface The logger instance to be used for messages processing. - */ - private LoggerInterface $logger; - /** * Sets the PSR-3 logger used to save messages of this target. * - * @param LoggerInterface $logger The logger instance. + * @param LoggerInterface $logger The logger instance to be used for messages processing. */ - public function __construct(LoggerInterface $logger) + public function __construct(private LoggerInterface $logger) { - $this->logger = $logger; parent::__construct(); } diff --git a/src/StreamTarget.php b/src/StreamTarget.php index 908e11057..4b937e127 100644 --- a/src/StreamTarget.php +++ b/src/StreamTarget.php @@ -26,19 +26,11 @@ */ final class StreamTarget extends Target { - /** - * @var resource|string A string stream identifier or a stream resource. - * - * @psalm-var mixed - */ - private $stream; - /** * @param resource|string $stream A string stream identifier or a stream resource. */ - public function __construct($stream = 'php://stdout') + public function __construct(private $stream = 'php://stdout') { - $this->stream = $stream; parent::__construct(); } @@ -83,6 +75,7 @@ private function createStream() } } + /** @psalm-suppress DocblockTypeContradiction */ if (!is_resource($stream) || get_resource_type($stream) !== 'stream') { throw new InvalidArgumentException(sprintf( 'Invalid stream provided. It must be a string stream identifier or a stream resource, "%s" received.', diff --git a/tests/LoggerTest.php b/tests/LoggerTest.php index 44ce8a0c5..69b4a4046 100644 --- a/tests/LoggerTest.php +++ b/tests/LoggerTest.php @@ -96,7 +96,6 @@ public function __toString(): string * @dataProvider messageProvider * * @param $message - * @param string $expected */ public function testPsrLogInterfaceMethods($message, string $expected): void { @@ -163,10 +162,8 @@ public function invalidExcludedTracePathsProvider(): array /** * @dataProvider invalidExcludedTracePathsProvider - * - * @param mixed $list */ - public function testSetExcludedTracePathsThrowExceptionForNonStringList($list): void + public function testSetExcludedTracePathsThrowExceptionForNonStringList(mixed $list): void { $this->expectException(InvalidArgumentException::class); $this->logger->setExcludedTracePaths($list); @@ -199,10 +196,8 @@ public function invalidMessageLevelProvider(): array /** * @dataProvider invalidMessageLevelProvider - * - * @param mixed $level */ - public function testGetLevelNameThrowExceptionForInvalidMessageLevel($level): void + public function testGetLevelNameThrowExceptionForInvalidMessageLevel(mixed $level): void { $this->expectException(\Psr\Log\InvalidArgumentException::class); Logger::validateLevel($level); @@ -235,8 +230,6 @@ public function invalidListTargetProvider(): array /** * @dataProvider invalidListTargetProvider - * - * @param array $targetList */ public function testConstructorThrowExceptionForNonInstanceTarget(array $targetList): void { @@ -267,10 +260,6 @@ public function parseMessageProvider(): array /** * @dataProvider parseMessageProvider - * - * @param string $message - * @param array $context - * @param string $expected */ public function testParseMessage(string $message, array $context, string $expected): void { @@ -384,8 +373,8 @@ public function testDispatchWithFakeTarget2ThrowExceptionWhenCollect(): void [ $this->callback(function ($messages) use ($target1, $exception) { $message = $messages[0] ?? null; - $text = 'Unable to send log via ' . get_class($target1) . ': RuntimeException: some error'; - return (count($messages) === 1 && $message instanceof Message) + $text = 'Unable to send log via ' . $target1::class . ': RuntimeException: some error'; + return ((is_countable($messages) ? count($messages) : 0) === 1 && $message instanceof Message) && $message->level() === LogLevel::WARNING && $message->message() === $text && is_float($message->context('time')) @@ -416,7 +405,6 @@ public function testDispatchWithFakeTarget2ThrowExceptionWhenCollect(): void /** * Sets an inaccessible object property to a designated value. * - * @param Logger $logger * @param Message[] $messages * @param bool $revoke whether to make property inaccessible after setting. */ @@ -435,7 +423,6 @@ private function setInaccessibleMessages(Logger $logger, array $messages, bool $ /** * Gets an inaccessible object property. * - * @param Logger $logger * @param bool $revoke whether to make property inaccessible after getting. * * @return Message[] diff --git a/tests/Message/CategoryFilterTest.php b/tests/Message/CategoryFilterTest.php index dae811075..c64e74cd2 100644 --- a/tests/Message/CategoryFilterTest.php +++ b/tests/Message/CategoryFilterTest.php @@ -32,8 +32,6 @@ public function invalidCategoryMessageStructureProvider(): array /** * @dataProvider invalidCategoryMessageStructureProvider - * - * @param array $categories */ public function testIncludeThrowExceptionForInvalidCategoryMessageStructure(array $categories): void { @@ -43,8 +41,6 @@ public function testIncludeThrowExceptionForInvalidCategoryMessageStructure(arra /** * @dataProvider invalidCategoryMessageStructureProvider - * - * @param array $categories */ public function testExcludeThrowExceptionForInvalidCategoryMessageStructure(array $categories): void { diff --git a/tests/Message/FormatterTest.php b/tests/Message/FormatterTest.php index d1ca9922b..94d813773 100644 --- a/tests/Message/FormatterTest.php +++ b/tests/Message/FormatterTest.php @@ -50,13 +50,10 @@ public function __toString(): string /** * @dataProvider contextProvider - * - * @param array $context - * @param string $expected */ public function testDefaultFormat(array $context, string $expected): void { - $context = array_merge($context, ['category' => 'app', 'time' => 1508160390.6083]); + $context = array_merge($context, ['category' => 'app', 'time' => 1_508_160_390.6083]); $message = new Message(LogLevel::INFO, 'message', $context); $expected = '2017-10-16 13:26:30.608300 [info][app] message' . "\n\nMessage context:\n\n{$expected}\ncategory: 'app'\ntime: 1508160390.6083\n" @@ -66,13 +63,10 @@ public function testDefaultFormat(array $context, string $expected): void /** * @dataProvider contextProvider - * - * @param array $commonContext - * @param string $expected */ public function testDefaultFormatWithCommonContext(array $commonContext, string $expected): void { - $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1508160390.6083]); + $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1_508_160_390.6083]); $expected = '2017-10-16 13:26:30.608300 [info][app] message' . "\n\nMessage context:\n\ncategory: 'app'\ntime: 1508160390.6083" . "\n\nCommon context:\n\n{$expected}\n" @@ -83,10 +77,10 @@ public function testDefaultFormatWithCommonContext(array $commonContext, string public function testFormatWithSetFormat(): void { $this->formatter->setFormat(static function (Message $message, array $commonContext) { - $context = json_encode($commonContext); + $context = json_encode($commonContext, JSON_THROW_ON_ERROR); return "[{$message->level()}][{$message->context('category')}] {$message->message()}\n{$context}\n"; }); - $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1508160390.6083]); + $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1_508_160_390.6083]); $expected = "[info][app] message\n{\"foo\":\"bar\"}\n"; $this->assertSame($expected, $this->formatter->format($message, ['foo' => 'bar'])); @@ -94,10 +88,8 @@ public function testFormatWithSetFormat(): void public function testFormatWithSetFormatNotIncludingCommonContext(): void { - $this->formatter->setFormat(static function (Message $message) { - return "[{$message->level()}][{$message->context('category')}] {$message->message()}"; - }); - $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1508160390.6083]); + $this->formatter->setFormat(static fn (Message $message) => "[{$message->level()}][{$message->context('category')}] {$message->message()}"); + $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1_508_160_390.6083]); $expected = '[info][app] message'; $this->assertSame($expected, $this->formatter->format($message, ['foo' => 'bar'])); @@ -106,7 +98,7 @@ public function testFormatWithSetFormatNotIncludingCommonContext(): void public function testFormatWithSetPrefix(): void { $this->formatter->setPrefix(static fn () => 'Prefix: '); - $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1508160390.6083]); + $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1_508_160_390.6083]); $expected = '2017-10-16 13:26:30.608300 Prefix: [info][app] message' . "\n\nMessage context:\n\ncategory: 'app'\ntime: 1508160390.6083\n" ; @@ -116,7 +108,7 @@ public function testFormatWithSetPrefix(): void public function testFormatWithSetTimestampFormat(): void { $this->formatter->setTimestampFormat('Y-m-d H:i:s'); - $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1508160390.6083]); + $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1_508_160_390.6083]); $expected = '2017-10-16 13:26:30 [info][app] message' . "\n\nMessage context:\n\ncategory: 'app'\ntime: 1508160390.6083\n" ; @@ -144,7 +136,7 @@ static function (Message $message) { } ); - $time = 1508160390; + $time = 1_508_160_390; $message = new Message(LogLevel::INFO, 'message', ['category' => 'app', 'time' => $time]); $this->assertSame( @@ -156,7 +148,7 @@ static function (Message $message) { public function testFormatWithContextAndSetFormat(): void { $this->formatter->setFormat(static function (Message $message) { - $context = json_encode($message->context()); + $context = json_encode($message->context(), JSON_THROW_ON_ERROR); return "({$message->level()}) {$message->message()}, context: {$context}"; }); $message = new Message(LogLevel::INFO, 'message', ['foo' => 'bar', 'params' => ['baz' => true]]); @@ -166,7 +158,7 @@ public function testFormatWithContextAndSetFormat(): void public function testFormatWithTraceInContext(): void { - $timestamp = 1508160390; + $timestamp = 1_508_160_390; $this->formatter->setTimestampFormat('Y-m-d H:i:s'); $message = new Message( LogLevel::INFO, @@ -196,8 +188,6 @@ public function invalidCallableReturnStringProvider(): array /** * @dataProvider invalidCallableReturnStringProvider - * - * @param callable $value */ public function testFormatThrowExceptionForFormatCallableReturnNotString(callable $value): void { @@ -208,8 +198,6 @@ public function testFormatThrowExceptionForFormatCallableReturnNotString(callabl /** * @dataProvider invalidCallableReturnStringProvider - * - * @param callable $value */ public function testFormatMessageThrowExceptionForPrefixCallableReturnNotString(callable $value): void { diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 2931d909e..33c1e58de 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -39,8 +39,6 @@ public function levelProvider(): array /** * @dataProvider levelProvider - * - * @param string $level */ public function testConstructorAndLevel(string $level): void { @@ -77,10 +75,6 @@ public function parseMessageProvider(): array /** * @dataProvider parseMessageProvider - * - * @param string $message - * @param array $context - * @param string $expected */ public function testParseMessage(string $message, array $context, string $expected): void { diff --git a/tests/PsrTargetTest.php b/tests/PsrTargetTest.php index 87de08248..490114cc4 100644 --- a/tests/PsrTargetTest.php +++ b/tests/PsrTargetTest.php @@ -27,7 +27,7 @@ public function setUp(): void public function log($level, $message, array $context = []): void { - echo "{$level}: {$message}: " . json_encode($context); + echo "{$level}: {$message}: " . json_encode($context, JSON_THROW_ON_ERROR); } }); } @@ -48,16 +48,12 @@ public function messageProvider(): array /** * @dataProvider messageProvider - * - * @param string $level - * @param string $message - * @param array $context */ public function testPsrLogInterfaceMethods(string $level, string $message, array $context): void { $this->assertInstanceOf(LoggerInterface::class, $this->target->getLogger()); $this->target->collect([new Message($level, $message, $context)], true); - $this->expectOutputString("{$level}: {$message}: " . json_encode($context)); + $this->expectOutputString("{$level}: {$message}: " . json_encode($context, JSON_THROW_ON_ERROR)); } } diff --git a/tests/StreamTargetTest.php b/tests/StreamTargetTest.php index 920e44208..7281704b8 100644 --- a/tests/StreamTargetTest.php +++ b/tests/StreamTargetTest.php @@ -81,8 +81,6 @@ public function testExportThrowExceptionForErrorWritingToStream($stream): void /** * @param resource|string $stream - * - * @return StreamTarget */ private function createStreamTarget($stream): StreamTarget { @@ -91,9 +89,6 @@ private function createStreamTarget($stream): StreamTarget return $target; } - /** - * @param StreamTarget $target - */ private function exportStreamTarget(StreamTarget $target): void { $target->collect( diff --git a/tests/TargetTest.php b/tests/TargetTest.php index 25c4882b1..13eae6a42 100644 --- a/tests/TargetTest.php +++ b/tests/TargetTest.php @@ -69,9 +69,6 @@ public function filterProvider(): array /** * @dataProvider filterProvider - * - * @param array $filter - * @param array $expected */ public function testFilter(array $filter, array $expected): void { @@ -150,7 +147,7 @@ public function testFormatAndFormatTimestamp(): void $text = 'message'; $level = LogLevel::INFO; $category = 'application'; - $timestamp = 1508160390.6083; + $timestamp = 1_508_160_390.6083; $context = "\n\nMessage context:\n\ncategory: '{$category}'\ntime: {$timestamp}\n"; $this->target->setTimestampFormat('Y-m-d H:i:s'); @@ -165,7 +162,7 @@ public function testFormatAndFormatTimestamp(): void $this->collectOneAndExport($level, $text, ['category' => $category, 'time' => $timestamp]); $this->assertSame($expectedWithMicro, $this->target->formatMessages()); - $timestamp = 1508160390; + $timestamp = 1_508_160_390; $this->target->setTimestampFormat('Y-m-d H:i:s'); $context = "\n\nMessage context:\n\ncategory: '{$category}'\ntime: {$timestamp}\n"; @@ -185,7 +182,7 @@ public function testFormatTimestampWithoutContextParameters(): void $text = 'message'; $level = LogLevel::INFO; $category = 'application'; - $timestamp = 1508160390.6083; + $timestamp = 1_508_160_390.6083; $this->target->setTimestampFormat('Y-m-d H:i:s.u'); @@ -206,7 +203,7 @@ public function testFormatTimestampWithoutContextParameters(): void public function testFormatMessagesWithTraceInContext(): void { - $timestamp = 1508160390; + $timestamp = 1_508_160_390; $this->target->setTimestampFormat('Y-m-d H:i:s'); $this->collectOneAndExport( LogLevel::INFO, @@ -235,8 +232,6 @@ public function invalidStringListProvider(): array /** * @dataProvider invalidStringListProvider - * - * @param array $list */ public function testSetCategoriesThrowExceptionForNonStringList(array $list): void { @@ -246,8 +241,6 @@ public function testSetCategoriesThrowExceptionForNonStringList(array $list): vo /** * @dataProvider invalidStringListProvider - * - * @param array $list */ public function testSetExceptThrowExceptionForNonStringList(array $list): void { @@ -257,8 +250,6 @@ public function testSetExceptThrowExceptionForNonStringList(array $list): void /** * @dataProvider invalidStringListProvider - * - * @param array $list */ public function testSetLevelsThrowExceptionForNonStringList(array $list): void { @@ -268,9 +259,7 @@ public function testSetLevelsThrowExceptionForNonStringList(array $list): void public function testSetFormat(): void { - $this->target->setFormat(static function (Message $message) { - return "[{$message->level()}][{$message->context('category')}] {$message->message()}"; - }); + $this->target->setFormat(static fn (Message $message) => "[{$message->level()}][{$message->context('category')}] {$message->message()}"); $expected = '[info][app] message'; $this->collectOneAndExport(LogLevel::INFO, 'message', ['category' => 'app']); @@ -282,7 +271,7 @@ public function testSetPrefix(): void $this->target->setPrefix(static fn () => 'Prefix: '); $expected = '2017-10-16 13:26:30.608300 Prefix: [info][app] message' . "\n\nMessage context:\n\ncategory: 'app'\ntime: 1508160390.6083\n"; - $this->collectOneAndExport(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1508160390.6083]); + $this->collectOneAndExport(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1_508_160_390.6083]); $this->assertSame($expected, $this->target->formatMessages()); } @@ -318,9 +307,6 @@ public function collectMessageProvider(): array /** * @dataProvider collectMessageProvider - * - * @param array $messages - * @param bool $export */ public function testFormatMessagesWithSeparatorAndSetFormatAndSetPrefix(array $messages, bool $export): void { @@ -335,9 +321,6 @@ public function testFormatMessagesWithSeparatorAndSetFormatAndSetPrefix(array $m /** * @dataProvider collectMessageProvider - * - * @param array $messages - * @param bool $export */ public function testGetFormattedMessagesAndSetFormatAndSetPrefix(array $messages, bool $export): void { @@ -352,16 +335,11 @@ public function testGetFormattedMessagesAndSetFormatAndSetPrefix(array $messages /** * @dataProvider collectMessageProvider - * - * @param array $messages - * @param bool $export */ public function testSetExportIntervalAndSetFormat(array $messages, bool $export): void { $this->target->setExportInterval(3); - $this->target->setFormat(static function (Message $message) { - return "[{$message->level()}][{$message->context('category')}] {$message->message()}"; - }); + $this->target->setFormat(static fn (Message $message) => "[{$message->level()}][{$message->context('category')}] {$message->message()}"); $this->target->collect($messages, $export); $this->assertSame((int) $export, $this->target->getExportCount()); @@ -391,13 +369,10 @@ public function __toString(): string /** * @dataProvider contextProvider - * - * @param array $context - * @param string $expected */ public function testMessageContext(array $context, string $expected): void { - $context = array_merge($context, ['category' => 'app', 'time' => 1508160390.6083]); + $context = array_merge($context, ['category' => 'app', 'time' => 1_508_160_390.6083]); $this->collectOneAndExport(LogLevel::INFO, 'message', $context); $expected = '2017-10-16 13:26:30.608300 [info][app] message' . "\n\nMessage context:\n\n{$expected}\ncategory: 'app'\ntime: 1508160390.6083\n" @@ -407,14 +382,11 @@ public function testMessageContext(array $context, string $expected): void /** * @dataProvider contextProvider - * - * @param array $commonContext - * @param string $expected */ public function testSetCommonContext(array $commonContext, string $expected): void { $this->target->setCommonContext($commonContext); - $this->collectOneAndExport(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1508160390.6083]); + $this->collectOneAndExport(LogLevel::INFO, 'message', ['category' => 'app', 'time' => 1_508_160_390.6083]); $expected = '2017-10-16 13:26:30.608300 [info][app] message' . "\n\nMessage context:\n\ncategory: 'app'\ntime: 1508160390.6083" . "\n\nCommon context:\n\n{$expected}\n" @@ -426,9 +398,7 @@ public function testSetCommonContext(array $commonContext, string $expected): vo public function testSetFormatWithoutMessageContextAndSetCommonContext(): void { $this->target->setCommonContext($commonContext = ['foo' => 'bar', 'baz' => true]); - $this->target->setFormat(static function (Message $message, array $commonContext) { - return "[{$message->level()}] {$message->message()}, common context: " . json_encode($commonContext); - }); + $this->target->setFormat(static fn (Message $message, array $commonContext) => "[{$message->level()}] {$message->message()}, common context: " . json_encode($commonContext, JSON_THROW_ON_ERROR)); $this->collectOneAndExport(LogLevel::INFO, 'message'); $expected = '[info] message, common context: {"foo":"bar","baz":true}'; @@ -450,8 +420,6 @@ public function invalidCallableReturnStringProvider(): array /** * @dataProvider invalidCallableReturnStringProvider - * - * @param callable $value */ public function testFormatMessageThrowExceptionForFormatCallableReturnNotBoolean(callable $value): void { @@ -477,8 +445,6 @@ public function invalidMessageListProvider(): array /** * @dataProvider invalidMessageListProvider - * - * @param array $messageList */ public function testCollectThrowExceptionForNonInstanceMessages(array $messageList): void { @@ -488,8 +454,6 @@ public function testCollectThrowExceptionForNonInstanceMessages(array $messageLi /** * @dataProvider invalidCallableReturnStringProvider - * - * @param callable $value */ public function testFormatMessageThrowExceptionForPrefixCallableReturnNotBoolean(callable $value): void {