Skip to content
Open
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
7 changes: 7 additions & 0 deletions src/Configuration/ConfigurationRuleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Configuration;

use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Contract\Rector\RectorInterface;
use Rector\ValueObject\Configuration;
Expand All @@ -30,6 +31,12 @@ public function setConfiguration(Configuration $configuration): void
*/
public function filter(array $rectors): array
{
// deprecated rules only warn via DeprecatedRulesReporter; they must never run, as their
// refactor() throws to signal the deprecation - keep them out of the active set
$rectors = array_values(
array_filter($rectors, static fn (RectorInterface $rector): bool => ! $rector instanceof DeprecatedInterface)
);

if (! $this->configuration instanceof Configuration) {
return $rectors;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Configuration/ConfigurationRuleFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
use Rector\Php80\Rector\Class_\StringableForToStringRector;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\Transform\Rector\Class_\AddInterfaceByTraitRector;
use Rector\ValueObject\Configuration;

final class ConfigurationRuleFilterTest extends AbstractLazyTestCase
Expand Down Expand Up @@ -49,6 +50,20 @@ public function testWithoutPhpOnlyKeepsAllRules(): void
$this->assertSame([$stringableForToStringRector, $removeDeadInstanceOfRector], $filteredRectors);
}

public function testFiltersOutDeprecatedRules(): void
{
$removeDeadInstanceOfRector = $this->make(RemoveDeadInstanceOfRector::class);
$addInterfaceByTraitRector = $this->make(AddInterfaceByTraitRector::class);

$this->configurationRuleFilter->setConfiguration($this->createConfiguration(false));

$filteredRectors = $this->configurationRuleFilter->filter(
[$removeDeadInstanceOfRector, $addInterfaceByTraitRector]
);

$this->assertSame([$removeDeadInstanceOfRector], $filteredRectors);
}

private function createConfiguration(bool $isPhpOnly): Configuration
{
return new Configuration(isPhpOnly: $isPhpOnly);
Expand Down
Loading