mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-22 08:25:02 +02:00
rename DescribeCommand to GenerateRectorOverviewCommand
This commit is contained in:
parent
e627166174
commit
a079a29f6b
12
README.md
12
README.md
@ -105,18 +105,6 @@ Do you need to upgrade to **Symfony 4.0**, for example?
|
||||
vendor/bin/rector levels
|
||||
```
|
||||
|
||||
4. What does loaded Rectors do?
|
||||
|
||||
```bash
|
||||
vendor/bin/rector describe --level symfony33
|
||||
```
|
||||
|
||||
5. What all Rectors do?
|
||||
|
||||
```bash
|
||||
vendor/bin/rector describe --all
|
||||
```
|
||||
|
||||
### B. Custom Sets
|
||||
|
||||
1. Create `rector.yml` with desired Rectors:
|
||||
|
@ -79,7 +79,7 @@
|
||||
"bin/clean_levels.sh"
|
||||
],
|
||||
"phpstan": "vendor/bin/phpstan analyse packages src tests --level max",
|
||||
"update-docs": "bin/rector describe --all --format md > docs/AllRectorsOverview.md",
|
||||
"update-docs": "bin/rector generate-rector-overview > docs/AllRectorsOverview.md",
|
||||
"changelog": [
|
||||
"vendor/bin/changelog-linker dump-merges --in-categories",
|
||||
"vendor/bin/changelog-linker linkify"
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -34,11 +34,6 @@ final class DiffConsoleFormatter
|
||||
return $this->formatWithTemplate($diff, $this->template);
|
||||
}
|
||||
|
||||
public function bareFormat(string $diff): string
|
||||
{
|
||||
return $this->formatWithTemplate($diff, PHP_EOL . '%s' . PHP_EOL);
|
||||
}
|
||||
|
||||
private function formatWithTemplate(string $diff, string $template): string
|
||||
{
|
||||
return sprintf(
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Rector\ConsoleDiffer;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
|
||||
final class MarkdownDifferAndFormatter
|
||||
@ -25,7 +26,7 @@ final class MarkdownDifferAndFormatter
|
||||
$diff = $this->markdownDiffer->diff($old, $new);
|
||||
|
||||
// remove first line, just meta info added by UnifiedDiffOutputBuilder
|
||||
$diff = preg_replace("/^(.*\n){1}/", '', $diff);
|
||||
$diff = Strings::replace($diff, '#^(.*\n){1}#');
|
||||
|
||||
return $this->removeTrailingWhitespaces($diff);
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ parameters:
|
||||
- '#Call to function in_array\(\) with arguments string, array<array<string\|false>> and true will always evaluate to false#'
|
||||
|
||||
# known values
|
||||
- '#Method Rector\\Console\\Command\\DescribeCommand::getRectorsByInput\(\) should return array<Rector\\Contract\\Rector\\RectorInterface|Rector\\YamlRector\\Contract \\YamlRectorInterface> but returns array<int, object>#'
|
||||
- '#Cannot call method getAttribute\(\) on PhpParser\\Node\\Name\|null#'
|
||||
- '#Parameter \#2 \$str of function explode expects string, string\|null given#'
|
||||
- '#Cannot call method getName\(\) on Rector\\Builder\\Class_\\VariableInfo\|null#'
|
||||
|
@ -1,115 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Console\Command;
|
||||
|
||||
use Nette\Loaders\RobotLoader;
|
||||
use Rector\Configuration\Option;
|
||||
use Rector\Console\ConsoleStyle;
|
||||
use Rector\Console\Output\DescribeCommandReporter;
|
||||
use Rector\Contract\Rector\RectorInterface;
|
||||
use Rector\NodeTraverser\RectorNodeTraverser;
|
||||
use Rector\YamlRector\YamlFileProcessor;
|
||||
use ReflectionClass;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
||||
|
||||
final class DescribeCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var ConsoleStyle
|
||||
*/
|
||||
private $consoleStyle;
|
||||
|
||||
/**
|
||||
* @var RectorNodeTraverser
|
||||
*/
|
||||
private $rectorNodeTraverser;
|
||||
|
||||
/**
|
||||
* @var DescribeCommandReporter
|
||||
*/
|
||||
private $describeCommandReporter;
|
||||
|
||||
/**
|
||||
* @var YamlFileProcessor
|
||||
*/
|
||||
private $yamlFileProcessor;
|
||||
|
||||
public function __construct(
|
||||
ConsoleStyle $consoleStyle,
|
||||
RectorNodeTraverser $rectorNodeTraverser,
|
||||
DescribeCommandReporter $describeCommandReporter,
|
||||
YamlFileProcessor $yamlFileProcessor
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->consoleStyle = $consoleStyle;
|
||||
$this->rectorNodeTraverser = $rectorNodeTraverser;
|
||||
$this->describeCommandReporter = $describeCommandReporter;
|
||||
$this->yamlFileProcessor = $yamlFileProcessor;
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName(CommandNaming::classToName(self::class));
|
||||
$this->setDescription('Shows detailed description of loaded Rectors.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->writeHeadline($input);
|
||||
$this->describeCommandReporter->reportRectorsInFormat($this->getRectorsByInput($input));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RectorInterface[]
|
||||
*/
|
||||
private function getRectorsByInput(InputInterface $input): array
|
||||
{
|
||||
if ($input->getOption(Option::OPTION_LEVEL)) {
|
||||
return $this->rectorNodeTraverser->getRectors() + $this->yamlFileProcessor->getYamlRectors();
|
||||
}
|
||||
|
||||
$robotLoader = $this->createRobotLoaderForAllRectors();
|
||||
$robotLoader->rebuild();
|
||||
|
||||
$rectors = [];
|
||||
foreach ($robotLoader->getIndexedClasses() as $class => $filename) {
|
||||
$reflectionClass = new ReflectionClass($class);
|
||||
if ($reflectionClass->isAbstract()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var RectorInterface $rector */
|
||||
$rectors[] = $reflectionClass->newInstanceWithoutConstructor();
|
||||
}
|
||||
|
||||
return $rectors;
|
||||
}
|
||||
|
||||
private function createRobotLoaderForAllRectors(): RobotLoader
|
||||
{
|
||||
$robotLoader = new RobotLoader();
|
||||
|
||||
$robotLoader->addDirectory(__DIR__ . '/../../Rector');
|
||||
$robotLoader->addDirectory(__DIR__ . '/../../../packages');
|
||||
$robotLoader->setTempDirectory(sys_get_temp_dir() . '/_rector_finder');
|
||||
$robotLoader->acceptFiles = ['*Rector.php'];
|
||||
|
||||
return $robotLoader;
|
||||
}
|
||||
|
||||
private function writeHeadline(InputInterface $input): void
|
||||
{
|
||||
$headline = $input->getOption(Option::OPTION_LEVEL) ? sprintf(
|
||||
'# Rectors for %s level',
|
||||
$input->getOption(Option::OPTION_LEVEL)
|
||||
) : '# All Rectors Overview';
|
||||
$this->consoleStyle->writeln($headline);
|
||||
$this->consoleStyle->newLine();
|
||||
}
|
||||
}
|
256
src/Console/Command/GenerateRectorOverviewCommand.php
Normal file
256
src/Console/Command/GenerateRectorOverviewCommand.php
Normal file
@ -0,0 +1,256 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Console\Command;
|
||||
|
||||
use Nette\Loaders\RobotLoader;
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\Console\ConsoleStyle;
|
||||
use Rector\ConsoleDiffer\MarkdownDifferAndFormatter;
|
||||
use Rector\Contract\Rector\RectorInterface;
|
||||
use Rector\Contract\RectorDefinition\CodeSampleInterface;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
use ReflectionClass;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
||||
|
||||
final class GenerateRectorOverviewCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var ConsoleStyle
|
||||
*/
|
||||
private $consoleStyle;
|
||||
|
||||
/**
|
||||
* @var MarkdownDifferAndFormatter
|
||||
*/
|
||||
private $markdownDifferAndFormatter;
|
||||
|
||||
public function __construct(ConsoleStyle $consoleStyle, MarkdownDifferAndFormatter $markdownDifferAndFormatter)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->consoleStyle = $consoleStyle;
|
||||
$this->markdownDifferAndFormatter = $markdownDifferAndFormatter;
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName(CommandNaming::classToName(self::class));
|
||||
$this->setDescription('Generates markdown documentation of all Rectors.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->consoleStyle->writeln('# All Rectors Overview');
|
||||
$this->consoleStyle->newLine();
|
||||
|
||||
// @todo menu to project + general rectors
|
||||
|
||||
$rectorsByGroup = $this->groupRectors($this->getProjectsRectors());
|
||||
$this->printRectorsByGroup($rectorsByGroup);
|
||||
|
||||
$this->consoleStyle->writeln('---');
|
||||
|
||||
$rectorsByGroup = $this->groupRectors($this->getGeneralRectors());
|
||||
$this->printRectorsByGroup($rectorsByGroup);
|
||||
|
||||
// success
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RectorInterface[]
|
||||
*/
|
||||
private function getProjectsRectors(): array
|
||||
{
|
||||
return $this->getRectorsFromDirectory(
|
||||
[__DIR__ . '/../../../packages'],
|
||||
[__DIR__ . '/../../../packages/YamlRector']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RectorInterface[]
|
||||
*/
|
||||
private function getGeneralRectors(): array
|
||||
{
|
||||
return $this->getRectorsFromDirectory([__DIR__ . '/../../../src'], [__DIR__ . '/../../../packages/YamlRector']);
|
||||
}
|
||||
|
||||
private function printRector(RectorInterface $rector): void
|
||||
{
|
||||
$headline = $this->getRectorClassWithoutNamespace($rector);
|
||||
$this->consoleStyle->writeln(sprintf('### `%s`', $headline));
|
||||
|
||||
$this->consoleStyle->newLine();
|
||||
$this->consoleStyle->writeln(sprintf('- class: `%s`', get_class($rector)));
|
||||
|
||||
$rectorDefinition = $rector->getDefinition();
|
||||
if ($rectorDefinition->getDescription()) {
|
||||
$this->consoleStyle->newLine();
|
||||
$this->consoleStyle->writeln($rectorDefinition->getDescription());
|
||||
}
|
||||
|
||||
$this->consoleStyle->newLine();
|
||||
$this->consoleStyle->writeln('```diff');
|
||||
|
||||
[$codeBefore, $codeAfter] = $this->joinBeforeAndAfter($rectorDefinition->getCodeSamples());
|
||||
$diff = $this->markdownDifferAndFormatter->bareDiffAndFormatWithoutColors($codeBefore, $codeAfter);
|
||||
$this->consoleStyle->write($diff);
|
||||
|
||||
$this->consoleStyle->newLine();
|
||||
$this->consoleStyle->writeln('```');
|
||||
|
||||
$this->consoleStyle->newLine(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CodeSampleInterface[] $codeSamples
|
||||
* @return string[]
|
||||
*/
|
||||
private function joinBeforeAndAfter(array $codeSamples): array
|
||||
{
|
||||
$separator = PHP_EOL . PHP_EOL;
|
||||
|
||||
$codesBefore = [];
|
||||
$codesAfter = [];
|
||||
foreach ($codeSamples as $codeSample) {
|
||||
$codesBefore[] = $codeSample->getCodeBefore();
|
||||
$codesAfter[] = $codeSample->getCodeAfter();
|
||||
}
|
||||
|
||||
$codeBefore = implode($separator, $codesBefore);
|
||||
$codeAfter = implode($separator, $codesAfter);
|
||||
|
||||
return [$codeBefore, $codeAfter];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[] $rectors
|
||||
* @return RectorInterface[][]
|
||||
*/
|
||||
private function groupRectors(array $rectors): array
|
||||
{
|
||||
$rectorsByGroup = [];
|
||||
foreach ($rectors as $rector) {
|
||||
$rectorGroup = $this->detectGroupFromRectorClass(get_class($rector));
|
||||
$rectorsByGroup[$rectorGroup][] = $rector;
|
||||
}
|
||||
|
||||
return $rectorsByGroup;
|
||||
}
|
||||
|
||||
private function detectGroupFromRectorClass(string $rectorClass): string
|
||||
{
|
||||
$rectorClassParts = explode('\\', $rectorClass);
|
||||
|
||||
// basic Rectors
|
||||
if (Strings::match($rectorClass, '#^Rector\\\\Rector\\\\#')) {
|
||||
return $rectorClassParts[count($rectorClassParts) - 2];
|
||||
}
|
||||
|
||||
// Yaml
|
||||
if (Strings::match($rectorClass, '#^Rector\\\\YamlRector\\\\#')) {
|
||||
return 'Yaml';
|
||||
}
|
||||
|
||||
// Rector/<PackageGroup>/Rector/SomeRector
|
||||
if (count($rectorClassParts) === 4) {
|
||||
return $rectorClassParts[1];
|
||||
}
|
||||
|
||||
// Rector/<PackageGroup>/Rector/<PackageSubGroup>/SomeRector
|
||||
if (count($rectorClassParts) === 5) {
|
||||
return $rectorClassParts[1] . '\\' . $rectorClassParts[3];
|
||||
}
|
||||
|
||||
throw new ShouldNotHappenException(sprintf(
|
||||
'Failed to resolve group from Rector class. Implement a new one in %s',
|
||||
__METHOD__
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[][] $rectorsByGroup
|
||||
*/
|
||||
private function printMenu(array $rectorsByGroup): void
|
||||
{
|
||||
foreach ($rectorsByGroup as $group => $rectors) {
|
||||
$escapedGroup = str_replace('\\', '', $group);
|
||||
$escapedGroup = Strings::webalize($escapedGroup, '_');
|
||||
|
||||
$this->consoleStyle->writeln(sprintf('- [%s](#%s)', $group, $escapedGroup));
|
||||
}
|
||||
|
||||
$this->consoleStyle->newLine();
|
||||
}
|
||||
|
||||
private function getRectorClassWithoutNamespace(RectorInterface $rector): string
|
||||
{
|
||||
$rectorClass = get_class($rector);
|
||||
$rectorClassParts = explode('\\', $rectorClass);
|
||||
|
||||
return $rectorClassParts[count($rectorClassParts) - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $directories
|
||||
* @param string[] $directoriesToExclude
|
||||
* @return RectorInterface[]
|
||||
*/
|
||||
private function getRectorsFromDirectory(array $directories, array $directoriesToExclude = []): array
|
||||
{
|
||||
$robotLoader = new RobotLoader();
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
$robotLoader->addDirectory($directory);
|
||||
}
|
||||
foreach ($directoriesToExclude as $directoryToExclude) {
|
||||
$robotLoader->excludeDirectory($directoryToExclude);
|
||||
}
|
||||
|
||||
$robotLoader->setTempDirectory(sys_get_temp_dir() . '/_rector_finder');
|
||||
$robotLoader->acceptFiles = ['*Rector.php'];
|
||||
$robotLoader->rebuild();
|
||||
|
||||
$rectors = [];
|
||||
foreach ($robotLoader->getIndexedClasses() as $class => $filename) {
|
||||
$reflectionClass = new ReflectionClass($class);
|
||||
if ($reflectionClass->isAbstract()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rector = $reflectionClass->newInstanceWithoutConstructor();
|
||||
if (! $rector instanceof RectorInterface) {
|
||||
throw new ShouldNotHappenException(sprintf(
|
||||
'"%s" found something that looks like Rector but does not implements "%s" interface.',
|
||||
__METHOD__,
|
||||
RectorInterface::class
|
||||
));
|
||||
}
|
||||
|
||||
$rectors[] = $rector;
|
||||
}
|
||||
|
||||
return $rectors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[][] $rectorsByGroup
|
||||
*/
|
||||
private function printRectorsByGroup(array $rectorsByGroup): void
|
||||
{
|
||||
$this->printMenu($rectorsByGroup);
|
||||
|
||||
foreach ($rectorsByGroup as $group => $rectors) {
|
||||
$this->consoleStyle->writeln('## ' . $group);
|
||||
$this->consoleStyle->newLine();
|
||||
|
||||
foreach ($rectors as $rector) {
|
||||
$this->printRector($rector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Console\Output;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\Console\ConsoleStyle;
|
||||
use Rector\ConsoleDiffer\MarkdownDifferAndFormatter;
|
||||
use Rector\Contract\Rector\RectorInterface;
|
||||
use Rector\Contract\RectorDefinition\CodeSampleInterface;
|
||||
|
||||
final class DescribeCommandReporter
|
||||
{
|
||||
/**
|
||||
* @var ConsoleStyle
|
||||
*/
|
||||
private $consoleStyle;
|
||||
|
||||
/**
|
||||
* @var MarkdownDifferAndFormatter
|
||||
*/
|
||||
private $markdownDifferAndFormatter;
|
||||
|
||||
public function __construct(ConsoleStyle $consoleStyle, MarkdownDifferAndFormatter $markdownDifferAndFormatter)
|
||||
{
|
||||
$this->consoleStyle = $consoleStyle;
|
||||
$this->markdownDifferAndFormatter = $markdownDifferAndFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[] $rectors
|
||||
*/
|
||||
public function reportRectorsInFormat(array $rectors): void
|
||||
{
|
||||
$rectorsByGroup = $this->groupRectors($rectors);
|
||||
$this->printMenu($rectorsByGroup);
|
||||
|
||||
foreach ($rectorsByGroup as $group => $rectors) {
|
||||
$this->consoleStyle->writeln('## ' . $group);
|
||||
$this->consoleStyle->newLine();
|
||||
|
||||
foreach ($rectors as $rector) {
|
||||
$this->printWithMarkdownFormat($rector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function printWithMarkdownFormat(RectorInterface $rector): void
|
||||
{
|
||||
$rectorClass = get_class($rector);
|
||||
$rectorClassParts = explode('\\', $rectorClass);
|
||||
$headline = $rectorClassParts[count($rectorClassParts) - 1];
|
||||
|
||||
$this->consoleStyle->writeln(sprintf('### `%s`', $headline));
|
||||
|
||||
$this->consoleStyle->newLine();
|
||||
$this->consoleStyle->writeln(sprintf('- class: `%s`', $rectorClass));
|
||||
|
||||
$rectorDefinition = $rector->getDefinition();
|
||||
if ($rectorDefinition->getDescription()) {
|
||||
$this->consoleStyle->newLine();
|
||||
$this->consoleStyle->writeln($rectorDefinition->getDescription());
|
||||
}
|
||||
|
||||
$this->consoleStyle->newLine();
|
||||
$this->consoleStyle->writeln('```diff');
|
||||
|
||||
[$codeBefore, $codeAfter] = $this->joinBeforeAndAfter($rectorDefinition->getCodeSamples());
|
||||
$diff = $this->markdownDifferAndFormatter->bareDiffAndFormatWithoutColors($codeBefore, $codeAfter);
|
||||
$this->consoleStyle->write($diff);
|
||||
|
||||
$this->consoleStyle->newLine();
|
||||
$this->consoleStyle->writeln('```');
|
||||
|
||||
$this->consoleStyle->newLine(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CodeSampleInterface[] $codeSamples
|
||||
* @return string[]
|
||||
*/
|
||||
private function joinBeforeAndAfter(array $codeSamples): array
|
||||
{
|
||||
$separator = PHP_EOL . PHP_EOL;
|
||||
|
||||
$codesBefore = [];
|
||||
$codesAfter = [];
|
||||
foreach ($codeSamples as $codeSample) {
|
||||
$codesBefore[] = $codeSample->getCodeBefore();
|
||||
$codesAfter[] = $codeSample->getCodeAfter();
|
||||
}
|
||||
|
||||
$codeBefore = implode($separator, $codesBefore);
|
||||
$codeAfter = implode($separator, $codesAfter);
|
||||
|
||||
return [$codeBefore, $codeAfter];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[] $rectors
|
||||
* @return RectorInterface[][]
|
||||
*/
|
||||
private function groupRectors(array $rectors): array
|
||||
{
|
||||
$rectorsByGroup = [];
|
||||
|
||||
foreach ($rectors as $rector) {
|
||||
$rectorGroup = $this->detectGroupFromRectorClass(get_class($rector));
|
||||
$rectorsByGroup[$rectorGroup][] = $rector;
|
||||
}
|
||||
|
||||
return $rectorsByGroup;
|
||||
}
|
||||
|
||||
private function detectGroupFromRectorClass(string $rectorClass): string
|
||||
{
|
||||
$rectorClassParts = explode('\\', $rectorClass);
|
||||
|
||||
// basic Rectors
|
||||
if (Strings::match($rectorClass, '#^Rector\\\\(Yaml)?Rector#')) {
|
||||
return $rectorClassParts[count($rectorClassParts) - 2];
|
||||
}
|
||||
|
||||
// Rector/<PackageGroup>/Rector/SomeRector
|
||||
if (count($rectorClassParts) === 4) {
|
||||
return $rectorClassParts[1];
|
||||
}
|
||||
|
||||
// Rector/<PackageGroup>/Rector/<PackageSubGroup>/SomeRector
|
||||
if (count($rectorClassParts) === 5) {
|
||||
return $rectorClassParts[1] . '\\' . $rectorClassParts[3];
|
||||
}
|
||||
|
||||
// fallback
|
||||
return $rectorClassParts[count($rectorClassParts) - 2];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RectorInterface[][] $rectorsByGroup
|
||||
*/
|
||||
private function printMenu(array $rectorsByGroup): void
|
||||
{
|
||||
foreach ($rectorsByGroup as $group => $rectors) {
|
||||
$escapedGroup = str_replace('\\', '', $group);
|
||||
$escapedGroup = Strings::webalize($escapedGroup, '_');
|
||||
|
||||
$this->consoleStyle->writeln(sprintf('- [%s](#%s)', $group, $escapedGroup));
|
||||
}
|
||||
|
||||
$this->consoleStyle->newLine();
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ final class AnnotationReplacerRector extends AbstractPHPUnitRector
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
'[Dynamic] Turns defined annotations above properties and methods to their new values.',
|
||||
'Turns defined annotations above properties and methods to their new values.',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
|
@ -36,7 +36,7 @@ final class ArgumentAdderRector extends AbstractArgumentRector
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
'[Dynamic] This Rector adds new default arguments in calls of defined methods and class types.',
|
||||
'This Rector adds new default arguments in calls of defined methods and class types.',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
|
@ -56,7 +56,7 @@ final class ArgumentDefaultValueReplacerRector extends AbstractArgumentRector
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
'[Dynamic] Replaces defined map of arguments in defined methods and their calls.',
|
||||
'Replaces defined map of arguments in defined methods and their calls.',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
|
@ -39,7 +39,7 @@ final class ArgumentRemoverRector extends AbstractArgumentRector
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
'[Dynamic] Removes defined arguments in defined methods and their calls.',
|
||||
'Removes defined arguments in defined methods and their calls.',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
|
@ -55,7 +55,7 @@ final class ClassConstantReplacerRector extends AbstractRector
|
||||
*/
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Replaces defined class constants in their calls.', [
|
||||
return new RectorDefinition('Replaces defined class constants in their calls.', [
|
||||
new CodeSample('$value = SomeClass::OLD_CONSTANT;', '$value = SomeClass::NEW_CONSTANT;'),
|
||||
]);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ final class ClassReplacerRector extends AbstractRector
|
||||
*/
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Replaces defined classes by new ones.', [
|
||||
return new RectorDefinition('Replaces defined classes by new ones.', [
|
||||
new CodeSample('$value = new SomeOldClass;', '$value = new SomeNewClass;'),
|
||||
]);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ final class FluentReplaceRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Turns fluent interfaces to classic ones.', [
|
||||
return new RectorDefinition('Turns fluent interfaces to classic ones.', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
|
@ -34,7 +34,7 @@ final class FunctionToMethodCallRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Turns defined function calls to local method calls.', [
|
||||
return new RectorDefinition('Turns defined function calls to local method calls.', [
|
||||
new CodeSample('view("...", []);', '$this->render("...", []);'),
|
||||
]);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ final class MethodNameReplacerRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Turns method names to new ones.', [
|
||||
return new RectorDefinition('Turns method names to new ones.', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$someObject = new SomeClass;
|
||||
|
@ -33,7 +33,7 @@ final class NamespaceReplacerRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Replaces old namespace by new one.', [
|
||||
return new RectorDefinition('Replaces old namespace by new one.', [
|
||||
new ConfiguredCodeSample(
|
||||
'$someObject = new SomeOldNamespace\SomeClass;',
|
||||
'$someObject = new SomeNewNamespace\SomeClass;',
|
||||
|
@ -56,7 +56,7 @@ final class ParentTypehintedArgumentRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Changes defined parent class typehints.', [
|
||||
return new RectorDefinition('Changes defined parent class typehints.', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
interface SomeInterface
|
||||
|
@ -52,7 +52,7 @@ final class PropertyNameReplacerRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Replaces defined old properties by new ones.', [
|
||||
return new RectorDefinition('Replaces defined old properties by new ones.', [
|
||||
new CodeSample('$someObject->someOldProperty;', '$someObject->someNewProperty;'),
|
||||
]);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ final class PropertyToMethodRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Replaces properties assign calls be defined methods.', [
|
||||
return new RectorDefinition('Replaces properties assign calls be defined methods.', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$result = $object->property;
|
||||
|
@ -60,7 +60,7 @@ final class PseudoNamespaceToNamespaceRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Replaces defined Pseudo_Namespaces by Namespace\Ones.', [
|
||||
return new RectorDefinition('Replaces defined Pseudo_Namespaces by Namespace\Ones.', [
|
||||
new CodeSample('$someServie = Some_Object;', '$someServie = Some\Object;'),
|
||||
]);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ final class ReturnTypehintRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Changes defined return typehint of method and class.', [
|
||||
return new RectorDefinition('Changes defined return typehint of method and class.', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
|
@ -16,7 +16,7 @@ final class ValueObjectRemoverRector extends AbstractValueObjectRemoverRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Remove values objects and use directly the value.', [
|
||||
return new RectorDefinition('Remove values objects and use directly the value.', [
|
||||
new CodeSample('$name = new ValueObject("name");', '$name = "name";'),
|
||||
new CodeSample(
|
||||
'function someFunction(ValueObject $name) { }',
|
||||
|
@ -62,7 +62,7 @@ final class GetAndSetToMethodCallRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Turns defined `__get`/`__set` to specific method calls.', [
|
||||
return new RectorDefinition('Turns defined `__get`/`__set` to specific method calls.', [
|
||||
new CodeSample(
|
||||
'$someService = $container->someService;',
|
||||
'$someService = $container->getService("someService");'
|
||||
|
@ -66,7 +66,7 @@ final class ToStringToMethodCallRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Turns defined __toString() to specific method calls.', [
|
||||
return new RectorDefinition('Turns defined __toString() to specific method calls.', [
|
||||
new CodeSample('$result = (string) $someValue;', '$result = $someValue->someMethod();'),
|
||||
new CodeSample('$result = $someValue->__toString();', '$result = $someValue->someMethod();'),
|
||||
]);
|
||||
|
@ -53,7 +53,7 @@ final class UnsetAndIssetToMethodCallRector extends AbstractRector
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('[Dynamic] Turns defined `__isset`/`__unset` calls to specific method calls.', [
|
||||
return new RectorDefinition('Turns defined `__isset`/`__unset` calls to specific method calls.', [
|
||||
new CodeSample('isset($container["someKey"]);', '$container->hasService("someKey");'),
|
||||
new CodeSample('unset($container["someKey"])', '$container->removeService("someKey");'),
|
||||
]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user