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

keradus / PHP-CS-Fixer / 16715837382

04 Aug 2025 06:34AM UTC coverage: 94.728% (+0.01%) from 94.716%
16715837382

push

github

keradus
chore: switch to official checkstyle.xsd

28212 of 29782 relevant lines covered (94.73%)

45.91 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
final class DotsOutput implements ProgressOutputInterface
27
{
28
    /**
29
     * File statuses map.
30
     *
31
     * @var array<FileProcessed::STATUS_*, array{symbol: string, format: string, description: string}>
32
     */
33
    private const EVENT_STATUS_MAP = [
34
        FileProcessed::STATUS_NO_CHANGES => ['symbol' => '.', 'format' => '%s', 'description' => 'no changes'],
35
        FileProcessed::STATUS_FIXED => ['symbol' => 'F', 'format' => '<fg=green>%s</fg=green>', 'description' => 'fixed'],
36
        FileProcessed::STATUS_SKIPPED => ['symbol' => 'S', 'format' => '<fg=cyan>%s</fg=cyan>', 'description' => 'skipped (cached or empty file)'],
37
        FileProcessed::STATUS_INVALID => ['symbol' => 'I', 'format' => '<bg=red>%s</bg=red>', 'description' => 'invalid file syntax (file ignored)'],
38
        FileProcessed::STATUS_EXCEPTION => ['symbol' => 'E', 'format' => '<bg=red>%s</bg=red>', 'description' => 'error'],
39
        FileProcessed::STATUS_LINT => ['symbol' => 'E', 'format' => '<bg=red>%s</bg=red>', 'description' => 'error'],
40
    ];
41

42
    /** @readonly */
43
    private OutputContext $context;
44

45
    private int $processedFiles = 0;
46

47
    private int $symbolsPerLine;
48

49
    public function __construct(OutputContext $context)
50
    {
51
        $this->context = $context;
10✔
52

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

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

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

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

84
        ++$this->processedFiles;
8✔
85

86
        $symbolsOnCurrentLine = $this->processedFiles % $this->symbolsPerLine;
8✔
87
        $isLast = $this->processedFiles === $this->context->getFilesCount();
8✔
88

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

98
            if (!$isLast) {
8✔
99
                $this->getOutput()->writeln('');
4✔
100
            }
101
        }
102
    }
103

104
    public function printLegend(): void
105
    {
106
        $symbols = [];
×
107

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

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

117
        $this->getOutput()->write(\sprintf("\nLegend: %s\n", implode(', ', $symbols)));
×
118
    }
119

120
    private function getOutput(): OutputInterface
121
    {
122
        return $this->context->getOutput();
8✔
123
    }
124
}
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