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

keradus / PHP-CS-Fixer / 17975696777

24 Sep 2025 11:13AM UTC coverage: 94.365% (-0.03%) from 94.396%
17975696777

push

github

web-flow
CI: Test docs generation only once per CI pipeline (#9089)

28500 of 30202 relevant lines covered (94.36%)

45.32 hits per line

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

0.0
/src/Console/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\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
    /** @TODO PHP 8.0 - remove the property */
38
    protected static $defaultName = 'documentation';
39

40
    /** @TODO PHP 8.0 - remove the property */
41
    protected static $defaultDescription = 'Dumps the documentation of the project into its "/doc" directory.';
42

43
    private Filesystem $filesystem;
44

45
    public function __construct(Filesystem $filesystem)
46
    {
47
        parent::__construct();
×
48
        $this->filesystem = $filesystem;
×
49
    }
50

51
    protected function configure(): void
52
    {
53
        $this->setAliases(['doc']);
×
54
    }
55

56
    protected function execute(InputInterface $input, OutputInterface $output): int
57
    {
58
        $locator = new DocumentationLocator();
×
59

60
        $fixerFactory = new FixerFactory();
×
61
        $fixerFactory->registerBuiltInFixers();
×
62
        $fixers = $fixerFactory->getFixers();
×
63

64
        $setDefinitions = RuleSets::getSetDefinitions();
×
65

66
        $fixerDocumentGenerator = new FixerDocumentGenerator($locator);
×
67
        $ruleSetDocumentationGenerator = new RuleSetDocumentationGenerator($locator);
×
68

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

75
        foreach ($fixers as $fixer) {
×
76
            $docForFixerRelativePaths[] = $locator->getFixerDocumentationFileRelativePath($fixer);
×
77
            $this->filesystem->dumpFile(
×
78
                $locator->getFixerDocumentationFilePath($fixer),
×
79
                $fixerDocumentGenerator->generateFixerDocumentation($fixer)
×
80
            );
×
81
        }
82

83
        foreach (
84
            (new Finder())->files()
×
85
                ->in($locator->getFixersDocumentationDirectoryPath())
×
86
                ->notPath($docForFixerRelativePaths) as $file
×
87
        ) {
88
            $this->filesystem->remove($file->getPathname());
×
89
        }
90

91
        // Fixer doc. index
92

93
        $this->filesystem->dumpFile(
×
94
            $locator->getFixersDocumentationIndexFilePath(),
×
95
            $fixerDocumentGenerator->generateFixersDocumentationIndex($fixers)
×
96
        );
×
97

98
        // RuleSet docs.
99

100
        foreach ((new Finder())->files()->in($locator->getRuleSetsDocumentationDirectoryPath()) as $file) {
×
101
            $this->filesystem->remove($file->getPathname());
×
102
        }
103

104
        $paths = [];
×
105

106
        foreach ($setDefinitions as $name => $definition) {
×
107
            $path = $locator->getRuleSetsDocumentationFilePath($name);
×
108
            $paths[$path] = $definition;
×
109
            $this->filesystem->dumpFile($path, $ruleSetDocumentationGenerator->generateRuleSetsDocumentation($definition, $fixers));
×
110
        }
111

112
        // RuleSet doc. index
113

114
        $this->filesystem->dumpFile(
×
115
            $locator->getRuleSetsDocumentationIndexFilePath(),
×
116
            $ruleSetDocumentationGenerator->generateRuleSetsDocumentationIndex($paths)
×
117
        );
×
118

119
        $output->writeln('Docs updated.');
×
120

121
        return 0;
×
122
    }
123
}
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