• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

keradus / PHP-CS-Fixer / 17252691116

26 Aug 2025 11:09PM UTC coverage: 94.743% (-0.01%) from 94.755%
17252691116

push

github

keradus
chore: apply phpdoc_tag_no_named_arguments

28313 of 29884 relevant lines covered (94.74%)

45.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.07
/src/Console/Output/Progress/DotsOutput.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz RumiƄski <dariusz.ruminski@gmail.com>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14

15
namespace PhpCsFixer\Console\Output\Progress;
16

17
use PhpCsFixer\Console\Output\OutputContext;
18
use PhpCsFixer\Runner\Event\FileProcessed;
19
use Symfony\Component\Console\Output\OutputInterface;
20

21
/**
22
 * Output writer to show the progress of a FixCommand using dots and meaningful letters.
23
 *
24
 * @internal
25
 *
26
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
27
 */
28
final class DotsOutput implements ProgressOutputInterface
29
{
30
    /**
31
     * File statuses map.
32
     *
33
     * @var array<FileProcessed::STATUS_*, array{symbol: string, format: string, description: string}>
34
     */
35
    private const EVENT_STATUS_MAP = [
36
        FileProcessed::STATUS_NO_CHANGES => ['symbol' => '.', 'format' => '%s', 'description' => 'no changes'],
37
        FileProcessed::STATUS_FIXED => ['symbol' => 'F', 'format' => '<fg=green>%s</fg=green>', 'description' => 'fixed'],
38
        FileProcessed::STATUS_SKIPPED => ['symbol' => 'S', 'format' => '<fg=cyan>%s</fg=cyan>', 'description' => 'skipped (cached or empty file)'],
39
        FileProcessed::STATUS_NON_MONOLITHIC => ['symbol' => 'M', 'format' => '<bg=magenta>%s</bg=magenta>', 'description' => 'skipped (non-monolithic)'],
40
        FileProcessed::STATUS_INVALID => ['symbol' => 'I', 'format' => '<bg=red>%s</bg=red>', 'description' => 'invalid file syntax (file ignored)'],
41
        FileProcessed::STATUS_EXCEPTION => ['symbol' => 'E', 'format' => '<bg=red>%s</bg=red>', 'description' => 'error'],
42
        FileProcessed::STATUS_LINT => ['symbol' => 'E', 'format' => '<bg=red>%s</bg=red>', 'description' => 'error'],
43
    ];
44

45
    /** @readonly */
46
    private OutputContext $context;
47

48
    private int $processedFiles = 0;
49

50
    private int $symbolsPerLine;
51

52
    public function __construct(OutputContext $context)
53
    {
54
        $this->context = $context;
10✔
55

56
        // max number of characters per line
57
        // - total length x 2 (e.g. "  1 / 123" => 6 digits and padding spaces)
58
        // - 11               (extra spaces, parentheses and percentage characters, e.g. " x / x (100%)")
59
        $this->symbolsPerLine = max(1, $context->getTerminalWidth() - \strlen((string) $context->getFilesCount()) * 2 - 11);
10✔
60
    }
61

62
    /**
63
     * This class is not intended to be serialized,
64
     * and cannot be deserialized (see __wakeup method).
65
     */
66
    public function __sleep(): array
67
    {
68
        throw new \BadMethodCallException('Cannot serialize '.self::class);
1✔
69
    }
70

71
    /**
72
     * Disable the deserialization of the class to prevent attacker executing
73
     * code by leveraging the __destruct method.
74
     *
75
     * @see https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection
76
     */
77
    public function __wakeup(): void
78
    {
79
        throw new \BadMethodCallException('Cannot unserialize '.self::class);
1✔
80
    }
81

82
    public function onFixerFileProcessed(FileProcessed $event): void
83
    {
84
        $status = self::EVENT_STATUS_MAP[$event->getStatus()];
8✔
85
        $this->getOutput()->write($this->getOutput()->isDecorated() ? \sprintf($status['format'], $status['symbol']) : $status['symbol']);
8✔
86

87
        ++$this->processedFiles;
8✔
88

89
        $symbolsOnCurrentLine = $this->processedFiles % $this->symbolsPerLine;
8✔
90
        $isLast = $this->processedFiles === $this->context->getFilesCount();
8✔
91

92
        if (0 === $symbolsOnCurrentLine || $isLast) {
8✔
93
            $this->getOutput()->write(\sprintf(
8✔
94
                '%s %'.\strlen((string) $this->context->getFilesCount()).'d / %d (%3d%%)',
8✔
95
                $isLast && 0 !== $symbolsOnCurrentLine ? str_repeat(' ', $this->symbolsPerLine - $symbolsOnCurrentLine) : '',
8✔
96
                $this->processedFiles,
8✔
97
                $this->context->getFilesCount(),
8✔
98
                round($this->processedFiles / $this->context->getFilesCount() * 100)
8✔
99
            ));
8✔
100

101
            if (!$isLast) {
8✔
102
                $this->getOutput()->writeln('');
4✔
103
            }
104
        }
105
    }
106

107
    public function printLegend(): void
108
    {
109
        $symbols = [];
×
110

111
        foreach (self::EVENT_STATUS_MAP as $status) {
×
112
            $symbol = $status['symbol'];
×
113
            if (isset($symbols[$symbol])) {
×
114
                continue;
×
115
            }
116

117
            $symbols[$symbol] = \sprintf('%s-%s', $this->getOutput()->isDecorated() ? \sprintf($status['format'], $symbol) : $symbol, $status['description']);
×
118
        }
119

120
        $this->getOutput()->write(\sprintf("\nLegend: %s\n", implode(', ', $symbols)));
×
121
    }
122

123
    private function getOutput(): OutputInterface
124
    {
125
        return $this->context->getOutput();
8✔
126
    }
127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc