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: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^3.2",
"driftingly/rector-laravel": "^2.0",
"driftingly/rector-laravel": "dev-main as 2.0",
"nette/robot-loader": "^4.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.0",
Expand Down
102 changes: 91 additions & 11 deletions composer.lock

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

5 changes: 5 additions & 0 deletions src/Enum/FindRule/GroupName.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ final class GroupName
* @var string
*/
public const TWIG = SetGroup::TWIG;

/**
* @var string
*/
public const LARAVEL = SetGroup::LARAVEL;
}
2 changes: 1 addition & 1 deletion src/Livewire/FindRuleComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function render(): View
GroupName::CORE => 'Core',
// GroupName::ATTRIBUTES => 'Attributes',
GroupName::SYMFONY => 'Symfony',
'laravel' => 'Laravel (community)',
GroupName::LARAVEL => 'Laravel (community)',
GroupName::PHPUNIT => 'PHPUnit',
GroupName::DOCTRINE => 'Doctrine',
GroupName::TWIG => 'Twig',
Expand Down
10 changes: 10 additions & 0 deletions src/RuleFilter/ValueObject/RuleMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\RuleFilter\ValueObject;

use App\Enum\FindRule\GroupName;
use App\Exception\ShouldNotHappenException;
use App\RuleFilter\ConfiguredDiffSamplesFactory;
use App\RuleFilter\Markdown\MarkdownDiffer;
Expand Down Expand Up @@ -144,6 +145,10 @@ public function getFilterScore(): ?int

public function belongToSetGroup(string $setGroup): bool
{
if ($this->isCommunityRule()) {
return $setGroup === GroupName::LARAVEL;
}

foreach ($this->sets as $set) {
if ($set->getGroupName() === $setGroup) {
return true;
Expand All @@ -152,4 +157,9 @@ public function belongToSetGroup(string $setGroup): bool

return false;
}

private function isCommunityRule(): bool
{
return str_starts_with($this->ruleClass, 'RectorLaravel');
}
}
44 changes: 44 additions & 0 deletions tests/RuleFilter/RuleFilterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace App\Tests\RuleFilter;

use App\Enum\FindRule\GroupName;
use App\RuleFilter\RuleFilter;
use App\RuleFilter\ValueObject\RuleMetadata;
use App\Tests\AbstractTestCase;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use RectorLaravel\Rector\ClassMethod\MigrateToSimplifiedAttributeRector;

final class RuleFilterTest extends AbstractTestCase
{
public function testFilterBySetGroup(): void
{
$ruleMetadataCore = new RuleMetadata(
RenameMethodRector::class,
'Some description',
[],
[],
'some-rector.php'
);
$ruleMetadataCommunity = new RuleMetadata(
MigrateToSimplifiedAttributeRector::class,
'Some description',
[],
[],
'some-rector.php'
);

$ruleFilter = $this->make(RuleFilter::class);
$filtered = $ruleFilter->filter(
[$ruleMetadataCore, $ruleMetadataCommunity],
null,
null,
GroupName::LARAVEL,
);

$this->assertCount(1, $filtered);
$this->assertSame($ruleMetadataCommunity->getRectorClass(), $filtered[0]->getRectorClass());
}
}
Loading