diff --git a/rector.php b/rector.php index cb3e8c8d..8f3ed734 100644 --- a/rector.php +++ b/rector.php @@ -16,6 +16,7 @@ '*/Fixture/*', StringClassNameToClassConstantRector::class => [ __DIR__ . '/src/Enum', + __DIR__ . '/src/Rules/Enum', __DIR__ . '/src/Testing/PHPUnitTestAnalyser.php', __DIR__ . '/src/Rules/NoEntityOutsideEntityNamespaceRule.php', __DIR__ . '/src/Rules/Symfony/CommandMustHaveAsCommandAttributeRule.php', diff --git a/src/Rules/Symfony/CommandMustHaveAsCommandAttributeRule.php b/src/Rules/Symfony/CommandMustHaveAsCommandAttributeRule.php index 45c48efe..672c9501 100644 --- a/src/Rules/Symfony/CommandMustHaveAsCommandAttributeRule.php +++ b/src/Rules/Symfony/CommandMustHaveAsCommandAttributeRule.php @@ -61,6 +61,11 @@ public function processNode(Node $node, Scope $scope): array return []; } + // do not require an attribute the project does not even have + if (! $this->reflectionProvider->hasClass(SymfonyAttribute::AS_COMMAND)) { + return []; + } + foreach ($node->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { if ($attr->name->toString() === SymfonyAttribute::AS_COMMAND) { diff --git a/src/Rules/Symfony/ConstraintMustHaveAttributeRule.php b/src/Rules/Symfony/ConstraintMustHaveAttributeRule.php index 8a5b2133..4a840d2e 100644 --- a/src/Rules/Symfony/ConstraintMustHaveAttributeRule.php +++ b/src/Rules/Symfony/ConstraintMustHaveAttributeRule.php @@ -55,6 +55,11 @@ public function processNode(Node $node, Scope $scope): array return []; } + // do not require an attribute when the validator component is not even installed + if (! $this->reflectionProvider->hasClass(SymfonyAttribute::CONSTRAINT)) { + return []; + } + $className = (string) $node->namespacedName; if (! $this->reflectionProvider->hasClass($className)) { return [];