Skip to content

Commit

Permalink
change to list of configs (#2694)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 20, 2022
1 parent ae31fb6 commit aee31ce
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions utils/Command/MissingInSetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
final class MissingInSetCommand extends Command
{
/**
* @var array<string, string>
* @var array<string, string[]>
*/
private const SETS_TO_RULES_DIRECTORIES = [
__DIR__ . '/../../config/set/code-quality.php' => __DIR__ . '/../../rules/CodeQuality/Rector',
__DIR__ . '/../../config/set/coding-style.php' => __DIR__ . '/../../rules/CodingStyle/Rector',
__DIR__ . '/../../config/set/dead-code.php' => __DIR__ . '/../../rules/DeadCode/Rector',
__DIR__ . '/../../config/set/early-return.php' => __DIR__ . '/../../rules/EarlyReturn/Rector',
__DIR__ . '/../../config/set/naming.php' => __DIR__ . '/../../rules/Naming/Rector',
__DIR__ . '/../../config/set/type-declaration.php' => __DIR__ . '/../../rules/TypeDeclaration/Rector',
private const RULES_DIRECTORY_TO_SET_CONFIGS = [
__DIR__ . '/../../rules/CodeQuality/Rector' => [__DIR__ . '/../../config/set/code-quality.php'],
__DIR__ . '/../../rules/CodingStyle/Rector' => [__DIR__ . '/../../config/set/coding-style.php'],
__DIR__ . '/../../rules/DeadCode/Rector' => [__DIR__ . '/../../config/set/dead-code.php'],
__DIR__ . '/../../rules/EarlyReturn/Rector' => [__DIR__ . '/../../config/set/early-return.php'],
__DIR__ . '/../../rules/Naming/Rector' => [__DIR__ . '/../../config/set/naming.php'],
__DIR__ . '/../../rules/TypeDeclaration/Rector' => [
__DIR__ . '/../../config/set/type-declaration.php',
__DIR__ . '/../../config/set/type-declaration-strict.php',
],
];

/**
Expand All @@ -46,8 +49,8 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
foreach (self::SETS_TO_RULES_DIRECTORIES as $setFile => $rulesDirectory) {
$shortClassesInSetFile = $this->resolveShortClassesFromSetFile($setFile);
foreach (self::RULES_DIRECTORY_TO_SET_CONFIGS as $rulesDirectory => $setFiles) {
$shortClassesInSetFile = $this->resolveShortClassesFromSetFiles($setFiles);
$existingShortRectorClasses = $this->findShortRectorClasses($rulesDirectory);

$shortRectorClassesNotInSetConfig = array_diff($existingShortRectorClasses, $shortClassesInSetFile);
Expand All @@ -56,11 +59,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
}

$setRealpath = (string) realpath($setFile);
$relativeFilePath = Strings::after($setRealpath, getcwd() . '/');
$this->symfonyStyle->title('We could not find there rules in configs');

foreach ($setFiles as $setFile) {
$setRealpath = (string) realpath($setFile);
$relativeFilePath = Strings::after($setRealpath, getcwd() . '/');

$this->symfonyStyle->writeln(' * ' . $relativeFilePath);
}

$this->symfonyStyle->newLine(1);

$title = sprintf('In "%s" config we could not find', $relativeFilePath);
$this->symfonyStyle->title($title);
$this->symfonyStyle->listing($shortRectorClassesNotInSetConfig);
$this->symfonyStyle->newLine(1);
}
Expand All @@ -69,16 +78,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

/**
* @param string[] $setFiles
* @return string[]
*/
private function resolveShortClassesFromSetFile(string $setFile): array
private function resolveShortClassesFromSetFiles(array $setFiles): array
{
$setFileContents = FileSystem::read($setFile);
$matches = Strings::matchAll($setFileContents, self::SHORT_CLASS_REGEX);

$shortClasses = [];
foreach ($matches as $match) {
$shortClasses[] = $match['short_class_name'];

foreach ($setFiles as $setFile) {
$setFileContents = FileSystem::read($setFile);
$matches = Strings::matchAll($setFileContents, self::SHORT_CLASS_REGEX);

foreach ($matches as $match) {
$shortClasses[] = $match['short_class_name'];
}
}

return $shortClasses;
Expand Down

0 comments on commit aee31ce

Please sign in to comment.