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

keradus / PHP-CS-Fixer / 17253322895

26 Aug 2025 11:52PM UTC coverage: 94.753% (+0.008%) from 94.745%
17253322895

push

github

keradus
add to git-blame-ignore-revs

28316 of 29884 relevant lines covered (94.75%)

45.64 hits per line

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

71.25
/src/Console/Application.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;
16

17
use PhpCsFixer\Console\Command\CheckCommand;
18
use PhpCsFixer\Console\Command\DescribeCommand;
19
use PhpCsFixer\Console\Command\FixCommand;
20
use PhpCsFixer\Console\Command\HelpCommand;
21
use PhpCsFixer\Console\Command\ListFilesCommand;
22
use PhpCsFixer\Console\Command\ListSetsCommand;
23
use PhpCsFixer\Console\Command\SelfUpdateCommand;
24
use PhpCsFixer\Console\Command\WorkerCommand;
25
use PhpCsFixer\Console\SelfUpdate\GithubClient;
26
use PhpCsFixer\Console\SelfUpdate\NewVersionChecker;
27
use PhpCsFixer\PharChecker;
28
use PhpCsFixer\Runner\Parallel\WorkerException;
29
use PhpCsFixer\ToolInfo;
30
use PhpCsFixer\Utils;
31
use Symfony\Component\Console\Application as BaseApplication;
32
use Symfony\Component\Console\Command\Command;
33
use Symfony\Component\Console\Command\CompleteCommand;
34
use Symfony\Component\Console\Command\DumpCompletionCommand;
35
use Symfony\Component\Console\Command\ListCommand;
36
use Symfony\Component\Console\Input\InputInterface;
37
use Symfony\Component\Console\Output\ConsoleOutputInterface;
38
use Symfony\Component\Console\Output\OutputInterface;
39

40
/**
41
 * @author Fabien Potencier <fabien@symfony.com>
42
 * @author Dariusz RumiƄski <dariusz.ruminski@gmail.com>
43
 *
44
 * @internal
45
 *
46
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
47
 */
48
final class Application extends BaseApplication
49
{
50
    public const NAME = 'PHP CS Fixer';
51
    public const VERSION = '3.86.1-DEV';
52
    public const VERSION_CODENAME = 'Alexander';
53

54
    /**
55
     * @readonly
56
     */
57
    private ToolInfo $toolInfo;
58
    private ?Command $executedCommand = null;
59

60
    public function __construct()
61
    {
62
        parent::__construct(self::NAME, self::VERSION);
2✔
63

64
        $this->toolInfo = new ToolInfo();
2✔
65

66
        // in alphabetical order
67
        $this->add(new DescribeCommand());
2✔
68
        $this->add(new CheckCommand($this->toolInfo));
2✔
69
        $this->add(new FixCommand($this->toolInfo));
2✔
70
        $this->add(new ListFilesCommand($this->toolInfo));
2✔
71
        $this->add(new ListSetsCommand());
2✔
72
        $this->add(new SelfUpdateCommand(
2✔
73
            new NewVersionChecker(new GithubClient()),
2✔
74
            $this->toolInfo,
2✔
75
            new PharChecker()
2✔
76
        ));
2✔
77
        $this->add(new WorkerCommand($this->toolInfo));
2✔
78
    }
79

80
    // polyfill for `add` method, as it is not available in Symfony 8.0
81
    public function add(Command $command): ?Command
82
    {
83
        if (method_exists($this, 'addCommand')) { // @phpstan-ignore function.impossibleType
2✔
84
            return $this->addCommand($command);
×
85
        }
86

87
        return parent::add($command);
2✔
88
    }
89

90
    public static function getMajorVersion(): int
91
    {
92
        return (int) explode('.', self::VERSION)[0];
1✔
93
    }
94

95
    public function doRun(InputInterface $input, OutputInterface $output): int
96
    {
97
        $stdErr = $output instanceof ConsoleOutputInterface
1✔
98
            ? $output->getErrorOutput()
×
99
            : ($input->hasParameterOption('--format', true) && 'txt' !== $input->getParameterOption('--format', null, true) ? null : $output);
1✔
100

101
        if (null !== $stdErr) {
1✔
102
            $warningsDetector = new WarningsDetector($this->toolInfo);
1✔
103
            $warningsDetector->detectOldVendor();
1✔
104
            $warningsDetector->detectOldMajor();
1✔
105
            $warningsDetector->detectNonMonolithic();
1✔
106
            $warnings = $warningsDetector->getWarnings();
1✔
107

108
            if (\count($warnings) > 0) {
1✔
109
                foreach ($warnings as $warning) {
×
110
                    $stdErr->writeln(\sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', $warning));
×
111
                }
112
                $stdErr->writeln('');
×
113
            }
114
        }
115

116
        $result = parent::doRun($input, $output);
1✔
117

118
        if (
119
            null !== $stdErr
×
120
            && $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE
×
121
        ) {
122
            $triggeredDeprecations = Utils::getTriggeredDeprecations();
×
123

124
            if (\count($triggeredDeprecations) > 0) {
×
125
                $stdErr->writeln('');
×
126
                $stdErr->writeln($stdErr->isDecorated() ? '<bg=yellow;fg=black;>Detected deprecations in use (they will stop working in next major release):</>' : 'Detected deprecations in use (they will stop working in next major release):');
×
127
                foreach ($triggeredDeprecations as $deprecation) {
×
128
                    $stdErr->writeln(\sprintf('- %s', $deprecation));
×
129
                }
130
            }
131
        }
132

133
        return $result;
×
134
    }
135

136
    /**
137
     * @internal
138
     */
139
    public static function getAbout(bool $decorated = false): string
140
    {
141
        $longVersion = \sprintf('%s <info>%s</info>', self::NAME, self::VERSION);
1✔
142

143
        $commit = '@git-commit@';
1✔
144
        $versionCommit = '';
1✔
145

146
        if ('@'.'git-commit@' !== $commit) { /** @phpstan-ignore-line as `$commit` is replaced during phar building */
1✔
147
            $versionCommit = substr($commit, 0, 7);
×
148
        }
149

150
        $about = implode('', [
1✔
151
            $longVersion,
1✔
152
            $versionCommit ? \sprintf(' <info>(%s)</info>', $versionCommit) : '', // @phpstan-ignore-line to avoid `Ternary operator condition is always true|false.`
1✔
153
            self::VERSION_CODENAME ? \sprintf(' <info>%s</info>', self::VERSION_CODENAME) : '', // @phpstan-ignore-line to avoid `Ternary operator condition is always true|false.`
1✔
154
            ' by <comment>Fabien Potencier</comment>, <comment>Dariusz Ruminski</comment> and <comment>contributors</comment>.',
1✔
155
        ]);
1✔
156

157
        if (false === $decorated) {
1✔
158
            return strip_tags($about);
×
159
        }
160

161
        return $about;
1✔
162
    }
163

164
    /**
165
     * @internal
166
     */
167
    public static function getAboutWithRuntime(bool $decorated = false): string
168
    {
169
        $about = self::getAbout(true)."\nPHP runtime: <info>".\PHP_VERSION.'</info>';
1✔
170
        if (false === $decorated) {
1✔
171
            return strip_tags($about);
×
172
        }
173

174
        return $about;
1✔
175
    }
176

177
    public function getLongVersion(): string
178
    {
179
        return self::getAboutWithRuntime(true);
1✔
180
    }
181

182
    protected function getDefaultCommands(): array
183
    {
184
        return [new HelpCommand(), new ListCommand(), new CompleteCommand(), new DumpCompletionCommand()];
2✔
185
    }
186

187
    /**
188
     * @throws \Throwable
189
     */
190
    protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output): int
191
    {
192
        $this->executedCommand = $command;
1✔
193

194
        return parent::doRunCommand($command, $input, $output);
1✔
195
    }
196

197
    protected function doRenderThrowable(\Throwable $e, OutputInterface $output): void
198
    {
199
        // Since parallel analysis utilises child processes, and they have their own output,
200
        // we need to capture the output of the child process to determine it there was an exception.
201
        // Default render format is not machine-friendly, so we need to override it for `worker` command,
202
        // in order to be able to easily parse exception data for further displaying on main process' side.
203
        if ($this->executedCommand instanceof WorkerCommand) {
1✔
204
            $output->writeln(WorkerCommand::ERROR_PREFIX.json_encode(
1✔
205
                [
1✔
206
                    'class' => \get_class($e),
1✔
207
                    'message' => $e->getMessage(),
1✔
208
                    'file' => $e->getFile(),
1✔
209
                    'line' => $e->getLine(),
1✔
210
                    'code' => $e->getCode(),
1✔
211
                    'trace' => $e->getTraceAsString(),
1✔
212
                ]
1✔
213
            ));
1✔
214

215
            return;
1✔
216
        }
217

218
        parent::doRenderThrowable($e, $output);
×
219

220
        if ($output->isVeryVerbose() && $e instanceof WorkerException) {
×
221
            $output->writeln('<comment>Original trace from worker:</comment>');
×
222
            $output->writeln('');
×
223
            $output->writeln($e->getOriginalTraceAsString());
×
224
            $output->writeln('');
×
225
        }
226
    }
227
}
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