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

keradus / PHP-CS-Fixer / 19958239208

05 Dec 2025 09:13AM UTC coverage: 93.181% (-1.0%) from 94.158%
19958239208

push

github

keradus
chore: .php-cs-fixer.dist.php - remove no longer needed rule, 'expectedDeprecation' annotation does not exist for long time

28928 of 31045 relevant lines covered (93.18%)

44.49 hits per line

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

70.79
/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\InitCommand;
22
use PhpCsFixer\Console\Command\ListFilesCommand;
23
use PhpCsFixer\Console\Command\ListSetsCommand;
24
use PhpCsFixer\Console\Command\SelfUpdateCommand;
25
use PhpCsFixer\Console\Command\WorkerCommand;
26
use PhpCsFixer\Console\SelfUpdate\GithubClient;
27
use PhpCsFixer\Console\SelfUpdate\NewVersionChecker;
28
use PhpCsFixer\Future;
29
use PhpCsFixer\PharChecker;
30
use PhpCsFixer\Runner\Parallel\WorkerException;
31
use PhpCsFixer\ToolInfo;
32
use Symfony\Component\Console\Application as BaseApplication;
33
use Symfony\Component\Console\Command\Command;
34
use Symfony\Component\Console\Command\CompleteCommand;
35
use Symfony\Component\Console\Command\DumpCompletionCommand;
36
use Symfony\Component\Console\Command\ListCommand;
37
use Symfony\Component\Console\Exception\CommandNotFoundException;
38
use Symfony\Component\Console\Input\InputInterface;
39
use Symfony\Component\Console\Output\ConsoleOutputInterface;
40
use Symfony\Component\Console\Output\OutputInterface;
41

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

56
    /**
57
     * @readonly
58
     */
59
    private ToolInfo $toolInfo;
60

61
    private ?Command $executedCommand = null;
62

63
    public function __construct()
64
    {
65
        parent::__construct(self::NAME, self::VERSION);
2✔
66

67
        $this->toolInfo = new ToolInfo();
2✔
68

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

84
    // polyfill for `add` method, as it is not available in Symfony 8.0
85
    public function add(Command $command): ?Command
86
    {
87
        if (method_exists($this, 'addCommand')) { // @phpstan-ignore-line
2✔
88
            return $this->addCommand($command);
2✔
89
        }
90

91
        return parent::add($command);
×
92
    }
93

94
    public static function getMajorVersion(): int
95
    {
96
        return (int) explode('.', self::VERSION)[0];
1✔
97
    }
98

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

105
        if (null !== $stdErr) {
1✔
106
            $warningsDetector = new WarningsDetector($this->toolInfo);
1✔
107
            $warningsDetector->detectOldVendor();
1✔
108
            $warningsDetector->detectOldMajor();
1✔
109

110
            try {
111
                $commandName = $this->getCommandName($input);
1✔
112
                if (null === $commandName) {
1✔
113
                    throw new CommandNotFoundException('No command name found.');
×
114
                }
115
                $command = $this->find($commandName);
1✔
116

117
                if (($command instanceof CheckCommand) || ($command instanceof FixCommand)) {
1✔
118
                    $warningsDetector->detectHigherPhpVersion();
×
119
                    $warningsDetector->detectNonMonolithic();
1✔
120
                }
121
            } catch (CommandNotFoundException $e) {
×
122
                // no-op
123
            }
124

125
            $warnings = $warningsDetector->getWarnings();
1✔
126

127
            if (\count($warnings) > 0) {
1✔
128
                foreach ($warnings as $warning) {
×
129
                    $stdErr->writeln(\sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', $warning));
×
130
                }
131
                $stdErr->writeln('');
×
132
            }
133
        }
134

135
        $result = parent::doRun($input, $output);
1✔
136

137
        if (
138
            null !== $stdErr
×
139
            && $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE
×
140
        ) {
141
            $triggeredDeprecations = Future::getTriggeredDeprecations();
×
142

143
            if (\count($triggeredDeprecations) > 0) {
×
144
                $stdErr->writeln('');
×
145
                $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):');
×
146
                foreach ($triggeredDeprecations as $deprecation) {
×
147
                    $stdErr->writeln(\sprintf('- %s', $deprecation));
×
148
                }
149
            }
150
        }
151

152
        return $result;
×
153
    }
154

155
    /**
156
     * @internal
157
     */
158
    public static function getAbout(bool $decorated = false): string
159
    {
160
        $longVersion = \sprintf('%s <info>%s</info>', self::NAME, self::VERSION);
1✔
161

162
        $commit = '@git-commit@';
1✔
163
        $versionCommit = '';
1✔
164

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

169
        $about = implode('', [
1✔
170
            $longVersion,
1✔
171
            $versionCommit ? \sprintf(' <info>(%s)</info>', $versionCommit) : '', // @phpstan-ignore-line to avoid `Ternary operator condition is always true|false.`
1✔
172
            self::VERSION_CODENAME ? \sprintf(' <info>%s</info>', self::VERSION_CODENAME) : '', // @phpstan-ignore-line to avoid `Ternary operator condition is always true|false.`
1✔
173
            ' by <comment>Fabien Potencier</comment>, <comment>Dariusz Ruminski</comment> and <comment>contributors</comment>.',
1✔
174
        ]);
1✔
175

176
        if (false === $decorated) {
1✔
177
            return strip_tags($about);
×
178
        }
179

180
        return $about;
1✔
181
    }
182

183
    /**
184
     * @internal
185
     */
186
    public static function getAboutWithRuntime(bool $decorated = false): string
187
    {
188
        $about = self::getAbout(true)."\nPHP runtime: <info>".\PHP_VERSION.'</info>';
1✔
189
        if (false === $decorated) {
1✔
190
            return strip_tags($about);
×
191
        }
192

193
        return $about;
1✔
194
    }
195

196
    public function getLongVersion(): string
197
    {
198
        return self::getAboutWithRuntime(true);
1✔
199
    }
200

201
    protected function getDefaultCommands(): array
202
    {
203
        return [new HelpCommand(), new ListCommand(), new CompleteCommand(), new DumpCompletionCommand()];
2✔
204
    }
205

206
    /**
207
     * @throws \Throwable
208
     */
209
    protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output): int
210
    {
211
        $this->executedCommand = $command;
1✔
212

213
        return parent::doRunCommand($command, $input, $output);
1✔
214
    }
215

216
    protected function doRenderThrowable(\Throwable $e, OutputInterface $output): void
217
    {
218
        // Since parallel analysis utilises child processes, and they have their own output,
219
        // we need to capture the output of the child process to determine it there was an exception.
220
        // Default render format is not machine-friendly, so we need to override it for `worker` command,
221
        // in order to be able to easily parse exception data for further displaying on main process' side.
222
        if ($this->executedCommand instanceof WorkerCommand) {
1✔
223
            $output->writeln(WorkerCommand::ERROR_PREFIX.json_encode(
1✔
224
                [
1✔
225
                    'class' => \get_class($e),
1✔
226
                    'message' => $e->getMessage(),
1✔
227
                    'file' => $e->getFile(),
1✔
228
                    'line' => $e->getLine(),
1✔
229
                    'code' => $e->getCode(),
1✔
230
                    'trace' => $e->getTraceAsString(),
1✔
231
                ],
1✔
232
                \JSON_THROW_ON_ERROR
1✔
233
            ));
1✔
234

235
            return;
1✔
236
        }
237

238
        parent::doRenderThrowable($e, $output);
×
239

240
        if ($output->isVeryVerbose() && $e instanceof WorkerException) {
×
241
            $output->writeln('<comment>Original trace from worker:</comment>');
×
242
            $output->writeln('');
×
243
            $output->writeln($e->getOriginalTraceAsString());
×
244
            $output->writeln('');
×
245
        }
246
    }
247
}
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