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

keradus / PHP-CS-Fixer / 22042339290

15 Feb 2026 08:14PM UTC coverage: 92.957% (-0.2%) from 93.171%
22042339290

push

github

keradus
test: check PHP env in CI jobs

29302 of 31522 relevant lines covered (92.96%)

44.04 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;
9✔
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);
9✔
60
    }
61

62
    /**
63
     * This class is not intended to be serialized,
64
     * and cannot be deserialized (see __wakeup method).
65
     */
66
    public function __serialize(): 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
     * @param array<string, mixed> $data
76
     *
77
     * @see https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection
78
     */
79
    public function __unserialize(array $data): void
80
    {
81
        throw new \BadMethodCallException('Cannot unserialize '.self::class);
1✔
82
    }
83

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

89
        ++$this->processedFiles;
8✔
90

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

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

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

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

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

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

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

125
    private function getOutput(): OutputInterface
126
    {
127
        return $this->context->getOutput();
8✔
128
    }
129
}
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