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

keradus / PHP-CS-Fixer / 16999983712

15 Aug 2025 09:42PM UTC coverage: 94.75% (-0.09%) from 94.839%
16999983712

push

github

keradus
ci: more self-fixing checks on lowest/highest PHP

28263 of 29829 relevant lines covered (94.75%)

45.88 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_NON_MONOLITHIC => ['symbol' => 'M', 'format' => '<bg=magenta>%s</bg=magenta>', 'description' => 'skipped (non-monolithic)'],
38
        FileProcessed::STATUS_INVALID => ['symbol' => 'I', 'format' => '<bg=red>%s</bg=red>', 'description' => 'invalid file syntax (file ignored)'],
39
        FileProcessed::STATUS_EXCEPTION => ['symbol' => 'E', 'format' => '<bg=red>%s</bg=red>', 'description' => 'error'],
40
        FileProcessed::STATUS_LINT => ['symbol' => 'E', 'format' => '<bg=red>%s</bg=red>', 'description' => 'error'],
41
    ];
42

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

46
    private int $processedFiles = 0;
47

48
    private int $symbolsPerLine;
49

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

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

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

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

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

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

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

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

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

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

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

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

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

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