From f8ce79838a000b8e99c5792e48078001f4541c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Rumi=C5=84ski?= Date: Tue, 17 Dec 2024 23:37:54 +0100 Subject: [PATCH] chore: DotsOutput - more const, better typing (#8318) --- dev-tools/phpstan/baseline.php | 6 ------ src/Console/Output/Progress/DotsOutput.php | 8 ++++---- src/Runner/Event/FileProcessed.php | 9 +++++++++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dev-tools/phpstan/baseline.php b/dev-tools/phpstan/baseline.php index 4befd0d8b9d..9bdf80b8228 100644 --- a/dev-tools/phpstan/baseline.php +++ b/dev-tools/phpstan/baseline.php @@ -325,12 +325,6 @@ 'count' => 1, 'path' => __DIR__ . '/../../src/Console/Output/ErrorOutput.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Offset int might not exist on array\\<1\\|2\\|3\\|4\\|5\\|6, array\\{symbol\\: string, format\\: string, description\\: string\\}\\>\\.$#', - 'identifier' => 'offsetAccess.notFound', - 'count' => 1, - 'path' => __DIR__ . '/../../src/Console/Output/Progress/DotsOutput.php', -]; $ignoreErrors[] = [ 'message' => '#^Offset string might not exist on array\\\\>\\.$#', 'identifier' => 'offsetAccess.notFound', diff --git a/src/Console/Output/Progress/DotsOutput.php b/src/Console/Output/Progress/DotsOutput.php index 57bbacb612c..221f65afe5e 100644 --- a/src/Console/Output/Progress/DotsOutput.php +++ b/src/Console/Output/Progress/DotsOutput.php @@ -30,7 +30,7 @@ final class DotsOutput implements ProgressOutputInterface * * @var array */ - private static array $eventStatusMap = [ + private const EVENT_STATUS_MAP = [ FileProcessed::STATUS_NO_CHANGES => ['symbol' => '.', 'format' => '%s', 'description' => 'no changes'], FileProcessed::STATUS_FIXED => ['symbol' => 'F', 'format' => '%s', 'description' => 'fixed'], FileProcessed::STATUS_SKIPPED => ['symbol' => 'S', 'format' => '%s', 'description' => 'skipped (cached or empty file)'], @@ -81,7 +81,7 @@ public function __wakeup(): void public function onFixerFileProcessed(FileProcessed $event): void { - $status = self::$eventStatusMap[$event->getStatus()]; + $status = self::EVENT_STATUS_MAP[$event->getStatus()]; $this->getOutput()->write($this->getOutput()->isDecorated() ? \sprintf($status['format'], $status['symbol']) : $status['symbol']); ++$this->processedFiles; @@ -108,9 +108,9 @@ public function printLegend(): void { $symbols = []; - foreach (self::$eventStatusMap as $status) { + foreach (self::EVENT_STATUS_MAP as $status) { $symbol = $status['symbol']; - if ('' === $symbol || isset($symbols[$symbol])) { + if (isset($symbols[$symbol])) { continue; } diff --git a/src/Runner/Event/FileProcessed.php b/src/Runner/Event/FileProcessed.php index e90206e5530..b9d4bcda1b7 100644 --- a/src/Runner/Event/FileProcessed.php +++ b/src/Runner/Event/FileProcessed.php @@ -37,11 +37,17 @@ final class FileProcessed extends Event public const STATUS_EXCEPTION = 5; public const STATUS_LINT = 6; + /** + * @var self::STATUS_* + */ private int $status; private ?string $fileRelativePath; private ?string $fileHash; + /** + * @param self::STATUS_* $status + */ public function __construct(int $status, ?string $fileRelativePath = null, ?string $fileHash = null) { $this->status = $status; @@ -49,6 +55,9 @@ public function __construct(int $status, ?string $fileRelativePath = null, ?stri $this->fileHash = $fileHash; } + /** + * @return self::STATUS_* + */ public function getStatus(): int { return $this->status;