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

PHP-CS-Fixer / PHP-CS-Fixer / 3721300657

pending completion
3721300657

push

github

GitHub
minor: Follow PSR12 ordered imports in Symfony ruleset (#6712)

9 of 9 new or added lines in 2 files covered. (100.0%)

22674 of 24281 relevant lines covered (93.38%)

39.08 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\ListDocumentGenerator;
20
use PhpCsFixer\Documentation\RuleSetDocumentationGenerator;
21
use PhpCsFixer\FixerFactory;
22
use PhpCsFixer\RuleSet\RuleSets;
23
use Symfony\Component\Console\Attribute\AsCommand;
24
use Symfony\Component\Console\Command\Command;
25
use Symfony\Component\Console\Input\InputInterface;
26
use Symfony\Component\Console\Output\OutputInterface;
27
use Symfony\Component\Filesystem\Filesystem;
28
use Symfony\Component\Finder\Finder;
29
use Symfony\Component\Finder\SplFileInfo;
30

31
/**
32
 * @internal
33
 */
34
#[AsCommand(name: 'documentation')]
35
final class DocumentationCommand extends Command
36
{
37
    /**
38
     * @var string
39
     */
40
    protected static $defaultName = 'documentation';
41

42
    protected function configure(): void
43
    {
44
        $this
×
45
            ->setAliases(['doc'])
×
46
            ->setDescription('Dumps the documentation of the project into its "/doc" directory.')
×
47
        ;
×
48
    }
49

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

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

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

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

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

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

79
        /** @var SplFileInfo $file */
80
        foreach (
81
            (new Finder())->files()
×
82
                ->in($locator->getFixersDocumentationDirectoryPath())
×
83
                ->notPath($docForFixerRelativePaths) as $file
×
84
        ) {
85
            $filesystem->remove($file->getPathname());
×
86
        }
87

88
        // Fixer doc. index
89

90
        $filesystem->dumpFile(
×
91
            $locator->getFixersDocumentationIndexFilePath(),
×
92
            $fixerDocumentGenerator->generateFixersDocumentationIndex($fixers)
×
93
        );
×
94

95
        // RuleSet docs.
96

97
        /** @var SplFileInfo $file */
98
        foreach ((new Finder())->files()->in($locator->getRuleSetsDocumentationDirectoryPath()) as $file) {
×
99
            $filesystem->remove($file->getPathname());
×
100
        }
101

102
        $paths = [];
×
103

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

110
        // RuleSet doc. index
111

112
        $filesystem->dumpFile(
×
113
            $locator->getRuleSetsDocumentationIndexFilePath(),
×
114
            $ruleSetDocumentationGenerator->generateRuleSetsDocumentationIndex($paths)
×
115
        );
×
116

117
        // List file / Appendix
118

119
        $filesystem->dumpFile(
×
120
            $locator->getListingFilePath(),
×
121
            $listDocumentGenerator->generateListingDocumentation($fixers)
×
122
        );
×
123

124
        $output->writeln('Docs updated.');
×
125

126
        return 0;
×
127
    }
128
}
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