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

PHP-CS-Fixer / PHP-CS-Fixer / 22808552760

07 Mar 2026 10:26PM UTC coverage: 92.913% (-0.01%) from 92.925%
22808552760

push

github

web-flow
chore: commands cleanup (#9478)

14 of 23 new or added lines in 12 files covered. (60.87%)

1 existing line in 1 file now uncovered.

29395 of 31637 relevant lines covered (92.91%)

43.93 hits per line

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

0.0
/src/Console/Internal/Command/DocumentationCommand.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\Internal\Command;
16

17
use PhpCsFixer\Documentation\DocumentationLocator;
18
use PhpCsFixer\Documentation\FixerDocumentGenerator;
19
use PhpCsFixer\Documentation\RuleSetDocumentationGenerator;
20
use PhpCsFixer\FixerFactory;
21
use PhpCsFixer\RuleSet\RuleSets;
22
use Symfony\Component\Console\Attribute\AsCommand;
23
use Symfony\Component\Console\Command\Command;
24
use Symfony\Component\Console\Input\InputInterface;
25
use Symfony\Component\Console\Output\OutputInterface;
26
use Symfony\Component\Filesystem\Filesystem;
27
use Symfony\Component\Finder\Finder;
28

29
/**
30
 * @internal
31
 *
32
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
33
 */
34
#[AsCommand(name: 'documentation', description: 'Dumps the documentation of the project into its "/doc" directory.')]
35
final class DocumentationCommand extends Command
36
{
37
    private Filesystem $filesystem;
38

39
    public function __construct(Filesystem $filesystem)
40
    {
NEW
41
        parent::__construct('documentation');
×
NEW
42
        $this->setDescription('Dumps the documentation of the project into its "/doc" directory.');
×
UNCOV
43
        $this->filesystem = $filesystem;
×
44
    }
45

46
    protected function configure(): void
47
    {
48
        $this->setAliases(['docs']);
×
49
    }
50

51
    protected function execute(InputInterface $input, OutputInterface $output): int
52
    {
53
        $locator = new DocumentationLocator();
×
54

55
        $fixerFactory = new FixerFactory();
×
56
        $fixerFactory->registerBuiltInFixers();
×
57
        $fixers = $fixerFactory->getFixers();
×
58

59
        $setDefinitions = RuleSets::getBuiltInSetDefinitions();
×
60

61
        $fixerDocumentGenerator = new FixerDocumentGenerator($locator);
×
62
        $ruleSetDocumentationGenerator = new RuleSetDocumentationGenerator($locator);
×
63

64
        // Array of existing fixer docs.
65
        // We first override existing files, and then we will delete files that are no longer needed.
66
        // We cannot remove all files first, as generation of docs is re-using existing docs to extract code-samples for
67
        // VersionSpecificCodeSample under incompatible PHP version.
68
        $docForFixerRelativePaths = [];
×
69

70
        foreach ($fixers as $fixer) {
×
71
            $docForFixerRelativePaths[] = $locator->getFixerDocumentationFileRelativePath($fixer);
×
72
            $this->filesystem->dumpFile(
×
73
                $locator->getFixerDocumentationFilePath($fixer),
×
74
                $fixerDocumentGenerator->generateFixerDocumentation($fixer),
×
75
            );
×
76
        }
77

78
        foreach (
79
            (new Finder())->files()
×
80
                ->in($locator->getFixersDocumentationDirectoryPath())
×
81
                ->notPath($docForFixerRelativePaths) as $file
×
82
        ) {
83
            $this->filesystem->remove($file->getPathname());
×
84
        }
85

86
        // Fixer doc. index
87

88
        $this->filesystem->dumpFile(
×
89
            $locator->getFixersDocumentationIndexFilePath(),
×
90
            $fixerDocumentGenerator->generateFixersDocumentationIndex($fixers),
×
91
        );
×
92

93
        // RuleSet docs.
94

95
        foreach ((new Finder())->files()->in($locator->getRuleSetsDocumentationDirectoryPath()) as $file) {
×
96
            $this->filesystem->remove($file->getPathname());
×
97
        }
98

99
        $paths = [];
×
100

101
        foreach ($setDefinitions as $name => $definition) {
×
102
            $path = $locator->getRuleSetsDocumentationFilePath($name);
×
103
            $paths[$path] = $definition;
×
104
            $this->filesystem->dumpFile($path, $ruleSetDocumentationGenerator->generateRuleSetsDocumentation($definition, $fixers));
×
105
        }
106

107
        // RuleSet doc. index
108

109
        $this->filesystem->dumpFile(
×
110
            $locator->getRuleSetsDocumentationIndexFilePath(),
×
111
            $ruleSetDocumentationGenerator->generateRuleSetsDocumentationIndex($paths),
×
112
        );
×
113

114
        $output->writeln('Docs updated.');
×
115

116
        return 0;
×
117
    }
118
}
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