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

keradus / PHP-CS-Fixer / 17702547357

13 Sep 2025 09:56PM UTC coverage: 94.55% (-0.1%) from 94.689%
17702547357

push

github

web-flow
docs: fix typo (#9060)

2 of 2 new or added lines in 1 file covered. (100.0%)

10 existing lines in 3 files now uncovered.

28416 of 30054 relevant lines covered (94.55%)

45.5 hits per line

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

92.75
/src/Console/Output/ErrorOutput.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;
16

17
use PhpCsFixer\Differ\DiffConsoleFormatter;
18
use PhpCsFixer\Error\Error;
19
use PhpCsFixer\Linter\LintingException;
20
use Symfony\Component\Console\Command\Command;
21
use Symfony\Component\Console\Formatter\OutputFormatter;
22
use Symfony\Component\Console\Output\OutputInterface;
23

24
/**
25
 * @readonly
26
 *
27
 * @internal
28
 *
29
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
30
 */
31
final class ErrorOutput
32
{
33
    private OutputInterface $output;
34

35
    private bool $isDecorated;
36

37
    public function __construct(OutputInterface $output)
38
    {
39
        $this->output = $output;
5✔
40
        $this->isDecorated = $output->isDecorated();
5✔
41
    }
42

43
    /**
44
     * @param list<Error> $errors
45
     */
46
    public function listErrors(string $process, array $errors): void
47
    {
48
        $this->output->writeln(['', \sprintf(
5✔
49
            'Files that were not fixed due to errors reported during %s:',
5✔
50
            $process
5✔
51
        )]);
5✔
52

53
        $showDetails = $this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE;
5✔
54
        $showTrace = $this->output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG;
5✔
55
        foreach ($errors as $i => $error) {
5✔
56
            $this->output->writeln(\sprintf('%4d) %s', $i + 1, $error->getFilePath()));
5✔
57
            $e = $error->getSource();
5✔
58
            if (!$showDetails || null === $e) {
5✔
59
                continue;
2✔
60
            }
61

62
            $class = \sprintf('[%s]', \get_class($e));
3✔
63
            $message = $e->getMessage();
3✔
64
            $code = $e->getCode();
3✔
65
            if (0 !== $code) {
3✔
66
                $message .= " ({$code})";
2✔
67
            }
68

69
            $length = max(\strlen($class), \strlen($message));
3✔
70
            $lines = [
3✔
71
                '',
3✔
72
                $class,
3✔
73
                $message,
3✔
74
                '',
3✔
75
            ];
3✔
76

77
            $this->output->writeln('');
3✔
78

79
            foreach ($lines as $line) {
3✔
80
                if (\strlen($line) < $length) {
3✔
81
                    $line .= str_repeat(' ', $length - \strlen($line));
3✔
82
                }
83

84
                $this->output->writeln(\sprintf('      <error>  %s  </error>', $this->prepareOutput($line)));
3✔
85
            }
86

87
            if ($showTrace && !$e instanceof LintingException) { // stack trace of lint exception is of no interest
3✔
88
                $this->output->writeln('');
1✔
89
                $stackTrace = $e->getTrace();
1✔
90
                foreach ($stackTrace as $trace) {
1✔
91
                    if (isset($trace['class']) && Command::class === $trace['class'] && 'run' === $trace['function']) {
1✔
92
                        $this->output->writeln('      [ ... ]');
×
93

94
                        break;
×
95
                    }
96

97
                    $this->outputTrace($trace);
1✔
98
                }
99
            }
100

101
            if (Error::TYPE_LINT === $error->getType() && 0 < \count($error->getAppliedFixers())) {
3✔
102
                $this->output->writeln('');
1✔
103
                $this->output->writeln(\sprintf('      Applied fixers: <comment>%s</comment>', implode(', ', $error->getAppliedFixers())));
1✔
104

105
                $diff = $error->getDiff();
1✔
106
                if (null !== $diff) {
1✔
107
                    $diffFormatter = new DiffConsoleFormatter(
1✔
108
                        $this->isDecorated,
1✔
109
                        \sprintf(
1✔
110
                            '<comment>      ---------- begin diff ----------</comment>%s%%s%s<comment>      ----------- end diff -----------</comment>',
1✔
111
                            \PHP_EOL,
1✔
112
                            \PHP_EOL
1✔
113
                        )
1✔
114
                    );
1✔
115

116
                    $this->output->writeln($diffFormatter->format($diff));
1✔
117
                }
118
            }
119
        }
120
    }
121

122
    /**
123
     * @param array{
124
     *     function?: string,
125
     *     line?: int,
126
     *     file?: string,
127
     *     class?: class-string,
128
     *     type?: '->'|'::',
129
     *     args?: list<mixed>,
130
     *     object?: object,
131
     * } $trace
132
     */
133
    private function outputTrace(array $trace): void
134
    {
135
        if (isset($trace['class'], $trace['type'], $trace['function'])) {
1✔
136
            $this->output->writeln(\sprintf(
1✔
137
                '      <comment>%s</comment>%s<comment>%s()</comment>',
1✔
138
                $this->prepareOutput($trace['class']),
1✔
139
                $this->prepareOutput($trace['type']),
1✔
140
                $this->prepareOutput($trace['function'])
1✔
141
            ));
1✔
142
        } elseif (isset($trace['function'])) {
×
143
            $this->output->writeln(\sprintf('      <comment>%s()</comment>', $this->prepareOutput($trace['function'])));
×
144
        }
145

146
        if (isset($trace['file'])) {
1✔
147
            $this->output->writeln(
1✔
148
                \sprintf('        in <info>%s</info>', $this->prepareOutput($trace['file']))
1✔
149
                .(isset($trace['line']) ? \sprintf(' at line <info>%d</info>', $trace['line']) : ' at unknown line')
1✔
150
            );
1✔
151
        }
152
    }
153

154
    private function prepareOutput(string $string): string
155
    {
156
        return $this->isDecorated
3✔
UNCOV
157
            ? OutputFormatter::escape($string)
×
158
            : $string;
3✔
159
    }
160
}
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