• 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/Documentation/ListDocumentGenerator.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\Documentation;
16

17
use PhpCsFixer\Console\Command\HelpCommand;
18
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
19
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
20
use PhpCsFixer\Fixer\FixerInterface;
21
use PhpCsFixer\FixerConfiguration\AliasedFixerOption;
22
use PhpCsFixer\FixerConfiguration\AllowedValueSubset;
23
use PhpCsFixer\FixerConfiguration\DeprecatedFixerOptionInterface;
24
use PhpCsFixer\RuleSet\RuleSet;
25
use PhpCsFixer\RuleSet\RuleSets;
26
use PhpCsFixer\Utils;
27

28
/**
29
 * @internal
30
 */
31
final class ListDocumentGenerator
32
{
33
    private DocumentationLocator $locator;
34

35
    public function __construct(DocumentationLocator $locator)
36
    {
37
        $this->locator = $locator;
×
38
    }
39

40
    /**
41
     * @param FixerInterface[] $fixers
42
     */
43
    public function generateListingDocumentation(array $fixers): string
44
    {
45
        usort(
×
46
            $fixers,
×
47
            static function (FixerInterface $fixer1, FixerInterface $fixer2): int {
×
48
                return strnatcasecmp($fixer1->getName(), $fixer2->getName());
×
49
            }
×
50
        );
×
51

52
        $documentation = <<<'RST'
×
53
=======================
54
List of Available Rules
55
=======================
56

57
RST;
×
58
        foreach ($fixers as $fixer) {
×
59
            $name = $fixer->getName();
×
60
            $definition = $fixer->getDefinition();
×
61
            $path = './rules/'.$this->locator->getFixerDocumentationFileRelativePath($fixer);
×
62

63
            $documentation .= "\n-  `{$name} <{$path}>`_\n";
×
64
            $documentation .= "\n   ".str_replace('`', '``', $definition->getSummary())."\n";
×
65

66
            $description = $definition->getDescription();
×
67

68
            if (null !== $description) {
×
69
                $documentation .= "\n   ".RstUtils::toRst($description, 3)."\n";
×
70
            }
71

72
            if ($fixer instanceof DeprecatedFixerInterface) {
×
73
                $documentation .= "\n   *warning deprecated*";
×
74
                $alternatives = $fixer->getSuccessorsNames();
×
75

76
                if (0 !== \count($alternatives)) {
×
77
                    $documentation .= RstUtils::toRst(sprintf(
×
78
                        '   Use %s instead.',
×
79
                        Utils::naturalLanguageJoinWithBackticks($alternatives)
×
80
                    ), 3);
×
81
                }
82

83
                $documentation .= "\n";
×
84
            }
85

86
            if ($fixer->isRisky()) {
×
87
                $documentation .= "\n   *warning risky* ".RstUtils::toRst($definition->getRiskyDescription(), 3)."\n";
×
88
            }
89

90
            if ($fixer instanceof ConfigurableFixerInterface) {
×
91
                $documentation .= "\n   Configuration options:\n";
×
92
                $configurationDefinition = $fixer->getConfigurationDefinition();
×
93

94
                foreach ($configurationDefinition->getOptions() as $option) {
×
95
                    $documentation .= "\n   - | ``{$option->getName()}``";
×
96
                    $documentation .= "\n     | {$option->getDescription()}";
×
97

98
                    if ($option instanceof DeprecatedFixerOptionInterface) {
×
99
                        $deprecationMessage = RstUtils::toRst($option->getDeprecationMessage(), 3);
×
100
                        $documentation .= "\n     | warning:: This option is deprecated and will be removed on next major version. {$deprecationMessage}";
×
101
                    }
102

103
                    if ($option instanceof AliasedFixerOption) {
×
104
                        $documentation .= "\n     | note:: The previous name of this option was ``{$option->getAlias()}`` but it is now deprecated and will be removed on next major version.";
×
105
                    }
106

107
                    $allowed = HelpCommand::getDisplayableAllowedValues($option);
×
108

109
                    if (null === $allowed) {
×
110
                        $allowedKind = 'Allowed types';
×
111
                        $allowed = array_map(
×
112
                            static fn ($value): string => '``'.$value.'``',
×
113
                            $option->getAllowedTypes(),
×
114
                        );
×
115
                    } else {
116
                        $allowedKind = 'Allowed values';
×
117
                        $allowed = array_map(static function ($value): string {
×
118
                            return $value instanceof AllowedValueSubset
×
119
                                ? 'a subset of ``'.HelpCommand::toString($value->getAllowedValues()).'``'
×
120
                                : '``'.HelpCommand::toString($value).'``';
×
121
                        }, $allowed);
×
122
                    }
123

124
                    $allowed = implode(', ', $allowed);
×
125
                    $documentation .= "\n     | {$allowedKind}: {$allowed}";
×
126

127
                    if ($option->hasDefault()) {
×
128
                        $default = HelpCommand::toString($option->getDefault());
×
129
                        $documentation .= "\n     | Default value: ``{$default}``";
×
130
                    } else {
131
                        $documentation .= "\n     | This option is required.";
×
132
                    }
133
                }
134

135
                $documentation .= "\n\n";
×
136
            }
137

138
            $ruleSetConfigs = [];
×
139

140
            foreach (RuleSets::getSetDefinitionNames() as $set) {
×
141
                $ruleSet = new RuleSet([$set => true]);
×
142

143
                if ($ruleSet->hasRule($name)) {
×
144
                    $ruleSetConfigs[$set] = $ruleSet->getRuleConfiguration($name);
×
145
                }
146
            }
147

148
            if ([] !== $ruleSetConfigs) {
×
149
                $plural = 1 !== \count($ruleSetConfigs) ? 's' : '';
×
150

151
                $documentation .= "\n   Part of rule set{$plural} ";
×
152

153
                foreach ($ruleSetConfigs as $set => $config) {
×
154
                    $ruleSetPath = $this->locator->getRuleSetsDocumentationFilePath($set);
×
155
                    $ruleSetPath = substr($ruleSetPath, strrpos($ruleSetPath, '/'));
×
156

157
                    $documentation .= "`{$set} <./ruleSets{$ruleSetPath}>`_ ";
×
158
                }
159

160
                $documentation = rtrim($documentation)."\n";
×
161
            }
162

163
            $reflectionObject = new \ReflectionObject($fixer);
×
164
            $className = str_replace('\\', '\\\\', $reflectionObject->getName());
×
165
            $fileName = $reflectionObject->getFileName();
×
166
            $fileName = str_replace('\\', '/', $fileName);
×
167
            $fileName = substr($fileName, strrpos($fileName, '/src/Fixer/') + 1);
×
168
            $fileName = "`Source {$className} <./../{$fileName}>`_";
×
169
            $documentation .= "\n   ".$fileName;
×
170
        }
171

172
        return $documentation."\n";
×
173
    }
174
}
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