Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/AllRectorsOverview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [Projects](#projects)
- [General](#general)
---

## Projects

Expand Down Expand Up @@ -10508,6 +10509,7 @@ Change $this->_view->assign = 5; to $this->render("...", $templateData);
<br>

---

## General

- [Core](#core)
Expand Down
17 changes: 3 additions & 14 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function doRun(InputInterface $input, OutputInterface $output): int

// skip in this case, since generate content must be clear from meta-info
$dumpCommands = [
CommandNaming::classToName(DumpRectorsCommand::class),
CommandNaming::classToName(DumpNodesCommand::class),
CommandNaming::classToName(DumpRectorsCommand::class),
];
if (in_array($input->getFirstArgument(), $dumpCommands, true)) {
return parent::doRun($input, $output);
Expand Down Expand Up @@ -135,19 +135,8 @@ private function shouldPrintMetaInformation(InputInterface $input): bool
return false;
}

$hasJsonOutput = (
$input->getParameterOption('--output-format') === JsonOutputFormatter::NAME ||
$input->getParameterOption('-o') === JsonOutputFormatter::NAME
);
if ($hasJsonOutput) {
return false;
}

$hasCheckstyleOutput = (
$input->getParameterOption('--output-format') === CheckstyleOutputFormatter::NAME ||
$input->getParameterOption('-o') === CheckstyleOutputFormatter::NAME
);
return ! $hasCheckstyleOutput;
$outputFormat = $input->getParameterOption(['-o', '--output-format']);
return ! in_array($outputFormat, [JsonOutputFormatter::NAME, CheckstyleOutputFormatter::NAME], true);
}

private function removeUnusedOptions(InputDefinition $inputDefinition): void
Expand Down
31 changes: 25 additions & 6 deletions utils/documentation-generator/src/Command/DumpRectorsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Rector\Utils\DocumentationGenerator\Command;

use Rector\Core\Configuration\Option;
use Rector\Core\Console\Command\AbstractCommand;
use Rector\Core\Testing\Finder\RectorsFinder;
use Rector\Utils\DocumentationGenerator\OutputFormatter\DumpRectors\MarkdownDumpRectorsOutputFormatter;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
Expand Down Expand Up @@ -38,18 +40,35 @@ protected function configure(): void
{
$this->setName(CommandNaming::classToName(self::class));
$this->setDescription('[DOCS] Dump overview of all Rectors');

$this->addArgument(
Option::SOURCE,
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'Directories with Rector rules'
);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$rulesRectors = $this->rectorsFinder->findInDirectories([
__DIR__ . '/../../../../rules',
__DIR__ . '/../../../../packages',
]);
$source = $input->getArgument(Option::SOURCE);

$isRectorProject = $source === [];

if ($source === []) {
// fallback to core Rectors
$rulesRectors = $this->rectorsFinder->findInDirectories([
__DIR__ . '/../../../../rules',
__DIR__ . '/../../../../packages',
]);

$generalRectors = $this->rectorsFinder->findInDirectory(__DIR__ . '/../../../../src');
$generalRectors = $this->rectorsFinder->findInDirectory(__DIR__ . '/../../../../src');
} else {
// custom directory
$rulesRectors = $this->rectorsFinder->findInDirectories($source);
$generalRectors = [];
}

$this->markdownDumpRectorsOutputFormatter->format($generalRectors, $rulesRectors);
$this->markdownDumpRectorsOutputFormatter->format($rulesRectors, $generalRectors, $isRectorProject);

return ShellCode::SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,48 +51,24 @@ public function __construct(
}

/**
* @param RectorInterface[] $genericRectors
* @param RectorInterface[] $packageRectors
* @param RectorInterface[] $generalRectors
*/
public function format(array $genericRectors, array $packageRectors): void
public function format(array $packageRectors, array $generalRectors, bool $isRectorProject): void
{
$totalRectorCount = count($genericRectors) + count($packageRectors);
$totalRectorCount = count($packageRectors) + count($generalRectors);

$this->symfonyStyle->writeln(sprintf('# All %d Rectors Overview', $totalRectorCount));
$this->symfonyStyle->newLine();

$this->symfonyStyle->writeln('- [Projects](#projects)');
$this->symfonyStyle->writeln('- [General](#general)');
$this->symfonyStyle->newLine();

$this->symfonyStyle->writeln('## Projects');
$this->symfonyStyle->newLine();

$this->printRectors($packageRectors);

$this->symfonyStyle->writeln('---');

$this->symfonyStyle->writeln('## General');
$this->symfonyStyle->newLine();
if ($isRectorProject) {
$this->symfonyStyle->writeln('- [Projects](#projects)');
$this->symfonyStyle->writeln('- [General](#general)');

$this->printRectors($genericRectors);
}

/**
* @param RectorInterface[] $rectors
*/
private function printRectors(array $rectors): void
{
$groupedRectors = $this->groupRectorsByPackage($rectors);
$this->printGroupsMenu($groupedRectors);

foreach ($groupedRectors as $group => $rectors) {
$this->symfonyStyle->writeln('## ' . $group);
$this->symfonyStyle->newLine();

foreach ($rectors as $rector) {
$this->printRector($rector);
}
$this->printRectorsWithHeadline($packageRectors, 'Projects');
$this->printRectorsWithHeadline($generalRectors, 'General');
} else {
$this->printRectors($packageRectors);
}
}

Expand Down Expand Up @@ -245,4 +221,40 @@ private function getClassRelativePath(string $className): string

return $rectorSmartFileInfo->getRelativeFilePathFromCwd();
}

/**
* @param RectorInterface[] $rectors
*/
private function printRectorsWithHeadline(array $rectors, string $headline): void
{
if (count($rectors) === 0) {
return;
}

$this->symfonyStyle->writeln('---');
$this->symfonyStyle->newLine();

$this->symfonyStyle->writeln('## ' . $headline);
$this->symfonyStyle->newLine();

$this->printRectors($rectors);
}

/**
* @param RectorInterface[] $rectors
*/
private function printRectors(array $rectors): void
{
$groupedRectors = $this->groupRectorsByPackage($rectors);
$this->printGroupsMenu($groupedRectors);

foreach ($groupedRectors as $group => $rectors) {
$this->symfonyStyle->writeln('## ' . $group);
$this->symfonyStyle->newLine();

foreach ($rectors as $rector) {
$this->printRector($rector);
}
}
}
}