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
92 changes: 46 additions & 46 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions src/FileSystem/RectorFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,29 +190,9 @@ private function findInDirectoriesAndCreateRuleMetadatas(array $directories, arr
$ruleDefinition->getCodeSamples(),
$currentRuleSets,
(string) $rectorReflectionClass->getFileName(),
$this->isDuplicatedLastName($findRectorClasses, $rectorReflectionClass->getShortName())
);
}

return $ruleMetadatas;
}

/**
* @param array<class-string<RectorInterface>> $findRectorClasses
*/
private function isDuplicatedLastName(array $findRectorClasses, string $lastName): bool
{
$count = 0;
foreach ($findRectorClasses as $findRectorClass) {
if (\str_ends_with($findRectorClass, '\\' . $lastName)) {
++$count;

if ($count === 2) {
return true;
}
}
}

return false;
}
}
20 changes: 1 addition & 19 deletions src/RuleFilter/ValueObject/RuleMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function __construct(
private array $codeSamples,
private readonly array $sets,
private readonly string $rectorRuleFilePath,
private readonly bool $sameNameInDifferentSet
) {
Assert::isAOf($ruleClass, RectorInterface::class);
Assert::allIsAOf($sets, RectorSet::class);
Expand All @@ -44,26 +43,9 @@ public function getRuleShortClass(): string
public function getSlug(): string
{
// turn "SomeRector" to "some-rector"
$lastSlug = str($this->getRuleShortClass())
return str($this->getRuleShortClass())
->snake('-')
->toString();

if ($this->sameNameInDifferentSet === false) {
return $lastSlug;
}

$currentSet = current($this->sets);

if ($currentSet === false) {
return $lastSlug;
}

$slug = $currentSet->getSlug();
if ($slug !== '') {
$slug .= '-';
}

return $slug . $lastSlug;
}

public function getDescription(): string
Expand Down
36 changes: 5 additions & 31 deletions tests/FileSystem/RectorFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\FileSystem\RectorFinder;
use App\Sets\RectorSetsTreeProvider;
use PHPUnit\Framework\TestCase;
use Rector\Php84\Rector\Class_\DeprecatedAnnotationToDeprecatedAttributeRector;

final class RectorFinderTest extends TestCase
{
Expand All @@ -24,43 +23,18 @@ public function testFindDuplicated(): void

$shortNames = [];
$longNames = [];
foreach ($foundRectors as $ruleMetadata) {
$shortNames[] = $ruleMetadata->getRuleShortClass();
$longNames[] = $ruleMetadata->getRectorClass();
foreach ($foundRectors as $foundRector) {
$shortNames[] = $foundRector->getRuleShortClass();
$longNames[] = $foundRector->getRectorClass();
}

$uniqueShortNames = array_unique($shortNames);
$uniqueLongNames = array_unique($longNames);

$this->assertNotSame(
$this->assertSame(
count($uniqueShortNames),
count($uniqueLongNames),
'There are duplicated short class names.'
);

// get duplicated short names and report different slug
$duplicatedShortNames = array_diff_key($shortNames, $uniqueShortNames);

$this->assertContains(
'DeprecatedAnnotationToDeprecatedAttributeRector',
$duplicatedShortNames,
'Expected DeprecatedAnnotationToDeprecatedAttributeRector to be one of the duplicated short names.'
'There are no duplicated short class names.'
);

foreach ($foundRectors as $foundRector) {
if ($foundRector->getRectorClass() === DeprecatedAnnotationToDeprecatedAttributeRector::class) {
$this->assertSame(
'php-php-84-deprecated-annotation-to-deprecated-attribute-rector',
$foundRector->getSlug()
);
}

if ($foundRector->getRectorClass() === \Rector\Php85\Rector\Const_\DeprecatedAnnotationToDeprecatedAttributeRector::class) {
$this->assertSame(
'php-php-85-deprecated-annotation-to-deprecated-attribute-rector',
$foundRector->getSlug()
);
}
}
}
}
Loading