Skip to content

Commit

Permalink
chore: DotsOutput - more const, better typing (PHP-CS-Fixer#8318)
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus authored Dec 17, 2024
1 parent a3726ef commit f8ce798
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 0 additions & 6 deletions dev-tools/phpstan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\\<string, class\\-string\\<PhpCsFixer\\\\Console\\\\Output\\\\Progress\\\\ProgressOutputInterface\\>\\>\\.$#',
'identifier' => 'offsetAccess.notFound',
Expand Down
8 changes: 4 additions & 4 deletions src/Console/Output/Progress/DotsOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class DotsOutput implements ProgressOutputInterface
*
* @var array<FileProcessed::STATUS_*, array{symbol: string, format: string, description: string}>
*/
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' => '<fg=green>%s</fg=green>', 'description' => 'fixed'],
FileProcessed::STATUS_SKIPPED => ['symbol' => 'S', 'format' => '<fg=cyan>%s</fg=cyan>', 'description' => 'skipped (cached or empty file)'],
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions src/Runner/Event/FileProcessed.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,27 @@ 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;
$this->fileRelativePath = $fileRelativePath;
$this->fileHash = $fileHash;
}

/**
* @return self::STATUS_*
*/
public function getStatus(): int
{
return $this->status;
Expand Down

0 comments on commit f8ce798

Please sign in to comment.