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

keradus / PHP-CS-Fixer / 16303177127

15 Jul 2025 06:22PM UTC coverage: 94.758% (-0.05%) from 94.806%
16303177127

push

github

keradus
bumped version

28199 of 29759 relevant lines covered (94.76%)

45.91 hits per line

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

70.89
/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\ListCommand;
34
use Symfony\Component\Console\Input\InputInterface;
35
use Symfony\Component\Console\Output\ConsoleOutputInterface;
36
use Symfony\Component\Console\Output\OutputInterface;
37

38
/**
39
 * @author Fabien Potencier <fabien@symfony.com>
40
 * @author Dariusz RumiƄski <dariusz.ruminski@gmail.com>
41
 *
42
 * @internal
43
 */
44
final class Application extends BaseApplication
45
{
46
    public const NAME = 'PHP CS Fixer';
47
    public const VERSION = '3.84.1-DEV';
48
    public const VERSION_CODENAME = 'Alexander';
49

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

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

60
        $this->toolInfo = new ToolInfo();
2✔
61

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

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

83
        return parent::add($command);
2✔
84
    }
85

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

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

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

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

111
        $result = parent::doRun($input, $output);
1✔
112

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

119
            if (\count($triggeredDeprecations) > 0) {
×
120
                $stdErr->writeln('');
×
121
                $stdErr->writeln($stdErr->isDecorated() ? '<bg=yellow;fg=black;>Detected deprecations in use:</>' : 'Detected deprecations in use:');
×
122
                foreach ($triggeredDeprecations as $deprecation) {
×
123
                    $stdErr->writeln(\sprintf('- %s', $deprecation));
×
124
                }
125
            }
126
        }
127

128
        return $result;
×
129
    }
130

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

138
        $commit = '@git-commit@';
1✔
139
        $versionCommit = '';
1✔
140

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

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

152
        if (false === $decorated) {
1✔
153
            return strip_tags($about);
×
154
        }
155

156
        return $about;
1✔
157
    }
158

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

169
        return $about;
1✔
170
    }
171

172
    public function getLongVersion(): string
173
    {
174
        return self::getAboutWithRuntime(true);
1✔
175
    }
176

177
    protected function getDefaultCommands(): array
178
    {
179
        return [new HelpCommand(), new ListCommand()];
2✔
180
    }
181

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

189
        return parent::doRunCommand($command, $input, $output);
1✔
190
    }
191

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

210
            return;
1✔
211
        }
212

213
        parent::doRenderThrowable($e, $output);
×
214

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