diff --git a/phpstan.neon b/phpstan.neon index 04115d03e40..4f4285e8116 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -137,6 +137,10 @@ parameters: message: '#Function "var_dump\(\)" cannot be used/left in the code#' path: src/functions/node_helper.php + - + message: '#Function "class_exists\(\)" cannot be used/left in the code#' + path: src/Configuration/OnlyRuleResolver.php + # lack of generic array in nikic/php-parser - '#Method (.*?) should return array but returns array#' diff --git a/src/Configuration/OnlyRuleResolver.php b/src/Configuration/OnlyRuleResolver.php index 1232506f083..69204dd1c51 100644 --- a/src/Configuration/OnlyRuleResolver.php +++ b/src/Configuration/OnlyRuleResolver.php @@ -4,7 +4,6 @@ namespace Rector\Configuration; -use PHPStan\Reflection\ReflectionProvider; use Rector\Contract\Rector\RectorInterface; use Rector\Exception\Configuration\RectorRuleNameAmbiguousException; use Rector\Exception\Configuration\RectorRuleNotFoundException; @@ -19,7 +18,6 @@ */ public function __construct( private array $rectors, - private ReflectionProvider $reflectionProvider ) { } @@ -104,16 +102,16 @@ public function resolve(string $rule): string */ private function isRectorRuleClass(string $className): bool { - if (! $this->reflectionProvider->hasClass($className)) { + if (! class_exists($className)) { return false; } - $classReflection = $this->reflectionProvider->getClass($className); - if ($classReflection->isAbstract()) { + $reflectionClass = new \ReflectionClass($className); + if ($reflectionClass->isAbstract()) { return false; } - return $classReflection->implementsInterface(RectorInterface::class); + return $reflectionClass->implementsInterface(RectorInterface::class); } private function createUnregisteredMessage(string $ruleClass): string diff --git a/tests/Configuration/OnlyRuleResolverTest.php b/tests/Configuration/OnlyRuleResolverTest.php index e2fdcedea04..303fc83e238 100644 --- a/tests/Configuration/OnlyRuleResolverTest.php +++ b/tests/Configuration/OnlyRuleResolverTest.php @@ -27,7 +27,6 @@ protected function setUp(): void $this->onlyRuleResolver = new OnlyRuleResolver( iterator_to_array($rectorConfig->tagged(RectorInterface::class)), - $this->make(ReflectionProvider::class) ); }