Fix bin/publish: copy docs.dist from project root

Fix bin/publish: use correct .env path for rspade_system
Fix bin/publish script: prevent grep exit code 1 from terminating script

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-10-21 02:08:33 +00:00
commit f6fac6c4bc
79758 changed files with 10547827 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace PhpCsFixer\Documentation;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\Preg;
use PhpCsFixer\Utils;
/**
* @readonly
*
* @internal
*/
final class DocumentationLocator
{
private string $path;
public function __construct()
{
$this->path = \dirname(__DIR__, 2).'/doc';
}
public function getFixersDocumentationDirectoryPath(): string
{
return $this->path.'/rules';
}
public function getFixersDocumentationIndexFilePath(): string
{
return $this->getFixersDocumentationDirectoryPath().'/index.rst';
}
public function getFixerDocumentationFilePath(FixerInterface $fixer): string
{
return $this->getFixersDocumentationDirectoryPath().'/'.Preg::replaceCallback(
'/^.*\\\(.+)\\\(.+)Fixer$/',
static fn (array $matches): string => Utils::camelCaseToUnderscore($matches[1]).'/'.Utils::camelCaseToUnderscore($matches[2]),
\get_class($fixer)
).'.rst';
}
public function getFixerDocumentationFileRelativePath(FixerInterface $fixer): string
{
return Preg::replace(
'#^'.preg_quote($this->getFixersDocumentationDirectoryPath(), '#').'/#',
'',
$this->getFixerDocumentationFilePath($fixer)
);
}
public function getRuleSetsDocumentationDirectoryPath(): string
{
return $this->path.'/ruleSets';
}
public function getRuleSetsDocumentationIndexFilePath(): string
{
return $this->getRuleSetsDocumentationDirectoryPath().'/index.rst';
}
public function getRuleSetsDocumentationFilePath(string $name): string
{
return $this->getRuleSetsDocumentationDirectoryPath().'/'.str_replace(':risky', 'Risky', ucfirst(substr($name, 1))).'.rst';
}
public function getUsageFilePath(): string
{
return $this->path.'/usage.rst';
}
}

View File

@@ -0,0 +1,418 @@
<?php
declare(strict_types=1);
/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace PhpCsFixer\Documentation;
use PhpCsFixer\Console\Command\HelpCommand;
use PhpCsFixer\Differ\FullDiffer;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
use PhpCsFixer\Fixer\ExperimentalFixerInterface;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\FixerConfiguration\AliasedFixerOption;
use PhpCsFixer\FixerConfiguration\AllowedValueSubset;
use PhpCsFixer\FixerConfiguration\DeprecatedFixerOptionInterface;
use PhpCsFixer\FixerDefinition\CodeSampleInterface;
use PhpCsFixer\FixerDefinition\FileSpecificCodeSampleInterface;
use PhpCsFixer\FixerDefinition\VersionSpecificCodeSampleInterface;
use PhpCsFixer\Preg;
use PhpCsFixer\RuleSet\RuleSet;
use PhpCsFixer\RuleSet\RuleSets;
use PhpCsFixer\StdinFileInfo;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Utils;
/**
* @readonly
*
* @internal
*/
final class FixerDocumentGenerator
{
private DocumentationLocator $locator;
private FullDiffer $differ;
public function __construct(DocumentationLocator $locator)
{
$this->locator = $locator;
$this->differ = new FullDiffer();
}
public function generateFixerDocumentation(FixerInterface $fixer): string
{
$name = $fixer->getName();
$title = "Rule ``{$name}``";
$titleLine = str_repeat('=', \strlen($title));
$doc = "{$titleLine}\n{$title}\n{$titleLine}";
$definition = $fixer->getDefinition();
$doc .= "\n\n".RstUtils::toRst($definition->getSummary());
$description = $definition->getDescription();
if (null !== $description) {
$description = RstUtils::toRst($description);
$doc .= <<<RST
Description
-----------
{$description}
RST;
}
$deprecationDescription = '';
if ($fixer instanceof DeprecatedFixerInterface) {
$deprecationDescription = <<<'RST'
This rule is deprecated and will be removed in the next major version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RST;
$alternatives = $fixer->getSuccessorsNames();
if (0 !== \count($alternatives)) {
$deprecationDescription .= RstUtils::toRst(\sprintf(
"\n\nYou should use %s instead.",
Utils::naturalLanguageJoinWithBackticks($alternatives)
), 0);
}
}
$experimentalDescription = '';
if ($fixer instanceof ExperimentalFixerInterface) {
$experimentalDescriptionRaw = RstUtils::toRst('Rule is not covered with backward compatibility promise, use it at your own risk. Rule\'s behaviour may be changed at any point, including rule\'s name; its options\' names, availability and allowed values; its default configuration. Rule may be even removed without prior notice. Feel free to provide feedback and help with determining final state of the rule.', 0);
$experimentalDescription = <<<RST
This rule is experimental
~~~~~~~~~~~~~~~~~~~~~~~~~
{$experimentalDescriptionRaw}
RST;
}
$riskyDescription = '';
$riskyDescriptionRaw = $definition->getRiskyDescription();
if (null !== $riskyDescriptionRaw) {
$riskyDescriptionRaw = RstUtils::toRst($riskyDescriptionRaw, 0);
$riskyDescription = <<<RST
Using this rule is risky
~~~~~~~~~~~~~~~~~~~~~~~~
{$riskyDescriptionRaw}
RST;
}
if ('' !== $deprecationDescription || '' !== $riskyDescription) {
$warningsHeader = 'Warning';
if ('' !== $deprecationDescription && '' !== $riskyDescription) {
$warningsHeader = 'Warnings';
}
$warningsHeaderLine = str_repeat('-', \strlen($warningsHeader));
$doc .= "\n\n".implode("\n", array_filter(
[
$warningsHeader,
$warningsHeaderLine,
$deprecationDescription,
$experimentalDescription,
$riskyDescription,
],
static fn (string $text): bool => '' !== $text
));
}
if ($fixer instanceof ConfigurableFixerInterface) {
$doc .= <<<'RST'
Configuration
-------------
RST;
$configurationDefinition = $fixer->getConfigurationDefinition();
foreach ($configurationDefinition->getOptions() as $option) {
$optionInfo = "``{$option->getName()}``";
$optionInfo .= "\n".str_repeat('~', \strlen($optionInfo));
if ($option instanceof DeprecatedFixerOptionInterface) {
$deprecationMessage = RstUtils::toRst($option->getDeprecationMessage());
$optionInfo .= "\n\n.. warning:: This option is deprecated and will be removed in the next major version. {$deprecationMessage}";
}
$optionInfo .= "\n\n".RstUtils::toRst($option->getDescription());
if ($option instanceof AliasedFixerOption) {
$optionInfo .= "\n\n.. note:: The previous name of this option was ``{$option->getAlias()}`` but it is now deprecated and will be removed in the next major version.";
}
$allowed = HelpCommand::getDisplayableAllowedValues($option);
if (null === $allowed) {
$allowedKind = 'Allowed types';
$allowed = array_map(
static fn (string $value): string => '``'.Utils::convertArrayTypeToList($value).'``',
$option->getAllowedTypes(),
);
} else {
$allowedKind = 'Allowed values';
$allowed = array_map(static fn ($value): string => $value instanceof AllowedValueSubset
? 'a subset of ``'.Utils::toString($value->getAllowedValues()).'``'
: '``'.Utils::toString($value).'``', $allowed);
}
$allowed = Utils::naturalLanguageJoin($allowed, '');
$optionInfo .= "\n\n{$allowedKind}: {$allowed}";
if ($option->hasDefault()) {
$default = Utils::toString($option->getDefault());
$optionInfo .= "\n\nDefault value: ``{$default}``";
} else {
$optionInfo .= "\n\nThis option is required.";
}
$doc .= "\n\n{$optionInfo}";
}
}
$samples = $definition->getCodeSamples();
if (0 !== \count($samples)) {
$doc .= <<<'RST'
Examples
--------
RST;
foreach ($samples as $index => $sample) {
$title = \sprintf('Example #%d', $index + 1);
$titleLine = str_repeat('~', \strlen($title));
$doc .= "\n\n{$title}\n{$titleLine}";
if ($fixer instanceof ConfigurableFixerInterface) {
if (null === $sample->getConfiguration()) {
$doc .= "\n\n*Default* configuration.";
} else {
$doc .= \sprintf(
"\n\nWith configuration: ``%s``.",
Utils::toString($sample->getConfiguration())
);
}
}
$doc .= "\n".$this->generateSampleDiff($fixer, $sample, $index + 1, $name);
}
}
$ruleSetConfigs = self::getSetsOfRule($name);
if ([] !== $ruleSetConfigs) {
$plural = 1 !== \count($ruleSetConfigs) ? 's' : '';
$doc .= <<<RST
Rule sets
---------
The rule is part of the following rule set{$plural}:\n\n
RST;
foreach ($ruleSetConfigs as $set => $config) {
$ruleSetPath = $this->locator->getRuleSetsDocumentationFilePath($set);
$ruleSetPath = substr($ruleSetPath, strrpos($ruleSetPath, '/'));
$configInfo = (null !== $config)
? " with config:\n\n ``".Utils::toString($config)."``\n"
: '';
$doc .= <<<RST
- `{$set} <./../../ruleSets{$ruleSetPath}>`_{$configInfo}\n
RST;
}
$doc = trim($doc);
}
$reflectionObject = new \ReflectionObject($fixer);
$className = str_replace('\\', '\\\\', $reflectionObject->getName());
$fileName = $reflectionObject->getFileName();
$fileName = str_replace('\\', '/', $fileName);
$fileName = substr($fileName, strrpos($fileName, '/src/Fixer/') + 1);
$fileName = "`{$className} <./../../../{$fileName}>`_";
$testFileName = Preg::replace('~.*\K/src/(?=Fixer/)~', '/tests/', $fileName);
$testFileName = Preg::replace('~PhpCsFixer\\\\\\\\\K(?=Fixer\\\\\\\)~', 'Tests\\\\\\\\', $testFileName);
$testFileName = Preg::replace('~(?= <|\.php>)~', 'Test', $testFileName);
$doc .= <<<RST
References
----------
- Fixer class: {$fileName}
- Test class: {$testFileName}
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.
RST;
$doc = str_replace("\t", '<TAB>', $doc);
return "{$doc}\n";
}
/**
* @internal
*
* @return array<string, null|array<string, mixed>>
*/
public static function getSetsOfRule(string $ruleName): array
{
$ruleSetConfigs = [];
foreach (RuleSets::getSetDefinitionNames() as $set) {
$ruleSet = new RuleSet([$set => true]);
if ($ruleSet->hasRule($ruleName)) {
$ruleSetConfigs[$set] = $ruleSet->getRuleConfiguration($ruleName);
}
}
return $ruleSetConfigs;
}
/**
* @param list<FixerInterface> $fixers
*/
public function generateFixersDocumentationIndex(array $fixers): string
{
$overrideGroups = [
'PhpUnit' => 'PHPUnit',
'PhpTag' => 'PHP Tag',
'Phpdoc' => 'PHPDoc',
];
usort($fixers, static fn (FixerInterface $a, FixerInterface $b): int => \get_class($a) <=> \get_class($b));
$documentation = <<<'RST'
=======================
List of Available Rules
=======================
RST;
$currentGroup = null;
foreach ($fixers as $fixer) {
$namespace = Preg::replace('/^.*\\\(.+)\\\.+Fixer$/', '$1', \get_class($fixer));
$group = $overrideGroups[$namespace] ?? Preg::replace('/(?<=[[:lower:]])(?=[[:upper:]])/', ' ', $namespace);
if ($group !== $currentGroup) {
$underline = str_repeat('-', \strlen($group));
$documentation .= "\n\n{$group}\n{$underline}\n";
$currentGroup = $group;
}
$path = './'.$this->locator->getFixerDocumentationFileRelativePath($fixer);
$attributes = [];
if ($fixer instanceof DeprecatedFixerInterface) {
$attributes[] = 'deprecated';
}
if ($fixer instanceof ExperimentalFixerInterface) {
$attributes[] = 'experimental';
}
if ($fixer->isRisky()) {
$attributes[] = 'risky';
}
$attributes = 0 === \count($attributes)
? ''
: ' *('.implode(', ', $attributes).')*';
$summary = str_replace('`', '``', $fixer->getDefinition()->getSummary());
$documentation .= <<<RST
- `{$fixer->getName()} <{$path}>`_{$attributes}
{$summary}
RST;
}
return "{$documentation}\n";
}
private function generateSampleDiff(FixerInterface $fixer, CodeSampleInterface $sample, int $sampleNumber, string $ruleName): string
{
if ($sample instanceof VersionSpecificCodeSampleInterface && !$sample->isSuitableFor(\PHP_VERSION_ID)) {
$existingFile = @file_get_contents($this->locator->getFixerDocumentationFilePath($fixer));
if (false !== $existingFile) {
Preg::match("/\\RExample #{$sampleNumber}\\R.+?(?<diff>\\R\\.\\. code-block:: diff\\R\\R.*?)\\R(?:\\R\\S|$)/s", $existingFile, $matches);
if (isset($matches['diff'])) {
return $matches['diff'];
}
}
$error = <<<RST
.. error::
Cannot generate diff for code sample #{$sampleNumber} of rule {$ruleName}:
the sample is not suitable for current version of PHP (%s).
RST;
return \sprintf($error, \PHP_VERSION);
}
$old = $sample->getCode();
$tokens = Tokens::fromCode($old);
$file = $sample instanceof FileSpecificCodeSampleInterface
? $sample->getSplFileInfo()
: new StdinFileInfo();
if ($fixer instanceof ConfigurableFixerInterface) {
$fixer->configure($sample->getConfiguration() ?? []);
}
$fixer->fix($file, $tokens);
$diff = $this->differ->diff($old, $tokens->generateCode());
$diff = Preg::replace('/@@[ \+\-\d,]+@@\n/', '', $diff);
$diff = Preg::replace('/\r/', '^M', $diff);
$diff = Preg::replace('/^ $/m', '', $diff);
$diff = Preg::replace('/\n$/', '', $diff);
$diff = RstUtils::indent($diff, 3);
return <<<RST
.. code-block:: diff
{$diff}
RST;
}
}

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace PhpCsFixer\Documentation;
use PhpCsFixer\Preg;
/**
* @internal
*/
final class RstUtils
{
private function __construct()
{
// cannot create instance of util. class
}
public static function toRst(string $string, int $indent = 0): string
{
$string = wordwrap(self::ensureProperInlineCode($string), 80 - $indent);
return 0 === $indent ? $string : self::indent($string, $indent);
}
public static function ensureProperInlineCode(string $string): string
{
return Preg::replace('/(?<!`)(`[^`]+`)(?!`)/', '`$1`', $string);
}
public static function indent(string $string, int $indent): string
{
return Preg::replace('/(\n)(?!\n|$)/', '$1'.str_repeat(' ', $indent), $string);
}
}

View File

@@ -0,0 +1,174 @@
<?php
declare(strict_types=1);
/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace PhpCsFixer\Documentation;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\Preg;
use PhpCsFixer\RuleSet\DeprecatedRuleSetDescriptionInterface;
use PhpCsFixer\RuleSet\RuleSetDescriptionInterface;
use PhpCsFixer\Utils;
/**
* @readonly
*
* @internal
*/
final class RuleSetDocumentationGenerator
{
private DocumentationLocator $locator;
public function __construct(DocumentationLocator $locator)
{
$this->locator = $locator;
}
/**
* @param list<FixerInterface> $fixers
*/
public function generateRuleSetsDocumentation(RuleSetDescriptionInterface $definition, array $fixers): string
{
$fixerNames = [];
foreach ($fixers as $fixer) {
$fixerNames[$fixer->getName()] = $fixer;
}
$title = "Rule set ``{$definition->getName()}``";
$titleLine = str_repeat('=', \strlen($title));
$doc = "{$titleLine}\n{$title}\n{$titleLine}\n\n".$definition->getDescription();
$warnings = [];
if ($definition instanceof DeprecatedRuleSetDescriptionInterface) {
$deprecationDescription = <<<'RST'
This rule set is deprecated and will be removed in the next major version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RST;
$alternatives = $definition->getSuccessorsNames();
if (0 !== \count($alternatives)) {
$deprecationDescription .= RstUtils::toRst(
\sprintf(
"\n\nYou should use %s instead.",
Utils::naturalLanguageJoinWithBackticks($alternatives)
),
0
);
} else {
$deprecationDescription .= 'No replacement available.';
}
$warnings[] = $deprecationDescription;
}
if ($definition->isRisky()) {
$warnings[] = <<<'RST'
This set contains rules that are risky
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using this rule set may lead to changes in your code's logic and behaviour. Use it with caution and review changes before incorporating them into your code base.
RST;
}
if ([] !== $warnings) {
$warningsHeader = 1 === \count($warnings) ? 'Warning' : 'Warnings';
$warningsHeaderLine = str_repeat('-', \strlen($warningsHeader));
$doc .= "\n\n".implode(
"\n",
[
$warningsHeader,
$warningsHeaderLine,
...$warnings,
]
);
}
$rules = $definition->getRules();
if ([] === $rules) {
$doc .= "\n\nThis is an empty set.";
} else {
$enabledRules = array_filter($rules, static fn ($config) => false !== $config);
$disabledRules = array_filter($rules, static fn ($config) => false === $config);
$listRules = function (array $rules) use (&$doc, $fixerNames): void {
foreach ($rules as $rule => $config) {
if (str_starts_with($rule, '@')) {
$ruleSetPath = $this->locator->getRuleSetsDocumentationFilePath($rule);
$ruleSetPath = substr($ruleSetPath, strrpos($ruleSetPath, '/'));
$doc .= "\n- `{$rule} <.{$ruleSetPath}>`_";
} else {
$path = Preg::replace(
'#^'.preg_quote($this->locator->getFixersDocumentationDirectoryPath(), '#').'/#',
'./../rules/',
$this->locator->getFixerDocumentationFilePath($fixerNames[$rule])
);
$doc .= "\n- `{$rule} <{$path}>`_";
}
if (!\is_bool($config)) {
$doc .= " with config:\n\n ``".Utils::toString($config)."``\n";
}
}
};
if ([] !== $enabledRules) {
$doc .= "\n\nRules\n-----\n";
$listRules($enabledRules);
}
if ([] !== $disabledRules) {
$doc .= "\n\nDisabled rules\n--------------\n";
$listRules($disabledRules);
}
}
return $doc."\n";
}
/**
* @param array<string, RuleSetDescriptionInterface> $setDefinitions
*/
public function generateRuleSetsDocumentationIndex(array $setDefinitions): string
{
$documentation = <<<'RST'
===========================
List of Available Rule sets
===========================
RST;
foreach ($setDefinitions as $path => $definition) {
$path = substr($path, strrpos($path, '/'));
$attributes = [];
if ($definition instanceof DeprecatedRuleSetDescriptionInterface) {
$attributes[] = 'deprecated';
}
$attributes = 0 === \count($attributes)
? ''
: ' *('.implode(', ', $attributes).')*';
$documentation .= "\n- `{$definition->getName()} <.{$path}>`_{$attributes}";
}
return $documentation."\n";
}
}