• 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

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
final class Application extends BaseApplication
47
{
48
    public const NAME = 'PHP CS Fixer';
49
    public const VERSION = '3.86.1-DEV';
50
    public const VERSION_CODENAME = 'Alexander';
51

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

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

62
        $this->toolInfo = new ToolInfo();
2✔
63

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

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

85
        return parent::add($command);
2✔
86
    }
87

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

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

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

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

114
        $result = parent::doRun($input, $output);
1✔
115

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

122
            if (\count($triggeredDeprecations) > 0) {
×
123
                $stdErr->writeln('');
×
124
                $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):');
×
125
                foreach ($triggeredDeprecations as $deprecation) {
×
126
                    $stdErr->writeln(\sprintf('- %s', $deprecation));
×
127
                }
128
            }
129
        }
130

131
        return $result;
×
132
    }
133

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

141
        $commit = '@git-commit@';
1✔
142
        $versionCommit = '';
1✔
143

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

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

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

159
        return $about;
1✔
160
    }
161

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

172
        return $about;
1✔
173
    }
174

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

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

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

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

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

213
            return;
1✔
214
        }
215

216
        parent::doRenderThrowable($e, $output);
×
217

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