diff --git a/config/static-rules.neon b/config/static-rules.neon index fa56ef94..91e1e862 100644 --- a/config/static-rules.neon +++ b/config/static-rules.neon @@ -8,7 +8,6 @@ rules: # domain - Symplify\PHPStanRules\Rules\Domain\RequireExceptionNamespaceRule - Symplify\PHPStanRules\Rules\Domain\RequireAttributeNamespaceRule - - Symplify\PHPStanRules\Rules\CheckAttributteArgumentClassExistsRule - Symplify\PHPStanRules\Rules\Enum\RequireUniqueEnumConstantRule - Symplify\PHPStanRules\Rules\ForbiddenParamTypeRemovalRule - Symplify\PHPStanRules\Rules\PreventParentMethodVisibilityOverrideRule diff --git a/docs/rules_overview.md b/docs/rules_overview.md index dc52ec54..5ba65570 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -1,4 +1,4 @@ -# 67 Rules Overview +# 66 Rules Overview ## AnnotateRegexClassConstWithRegexLinkRule @@ -65,34 +65,6 @@ class SomeClass
-## CheckAttributteArgumentClassExistsRule - -Class was not found - -- class: [`Symplify\PHPStanRules\Rules\CheckAttributteArgumentClassExistsRule`](../src/Rules/CheckAttributteArgumentClassExistsRule.php) - -```php -#[SomeAttribute(firstName: 'MissingClass::class')] -class SomeClass -{ -} -``` - -:x: - -
- -```php -#[SomeAttribute(firstName: ExistingClass::class)] -class SomeClass -{ -} -``` - -:+1: - -
- ## CheckClassNamespaceFollowPsr4Rule Class like namespace "%s" does not follow PSR-4 configuration in `composer.json` diff --git a/src/Rules/CheckAttributteArgumentClassExistsRule.php b/src/Rules/CheckAttributteArgumentClassExistsRule.php deleted file mode 100644 index 026db055..00000000 --- a/src/Rules/CheckAttributteArgumentClassExistsRule.php +++ /dev/null @@ -1,107 +0,0 @@ - - */ -final class CheckAttributteArgumentClassExistsRule implements Rule, DocumentedRuleInterface -{ - /** - * @var string - */ - public const ERROR_MESSAGE = 'Class was not found'; - - public function __construct( - private readonly ReflectionProvider $reflectionProvider, - ) { - } - - public function getNodeType(): string - { - return AttributeGroup::class; - } - - /** - * @param AttributeGroup $node - * @return string[] - */ - public function processNode(Node $node, Scope $scope): array - { - $ruleErrors = []; - - foreach ($node->attrs as $attribute) { - foreach ($attribute->args as $arg) { - $value = $arg->value; - if (! $this->isClassConstFetch($value)) { - continue; - } - - $valueType = $scope->getType($value); - if (! $valueType instanceof ConstantStringType) { - $ruleErrors[] = self::ERROR_MESSAGE; - continue; - } - - if ($this->reflectionProvider->hasClass($valueType->getValue())) { - continue; - } - - $ruleErrors[] = self::ERROR_MESSAGE; - } - } - - return $ruleErrors; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition(self::ERROR_MESSAGE, [ - new CodeSample( - <<<'CODE_SAMPLE' -#[SomeAttribute(firstName: 'MissingClass::class')] -class SomeClass -{ -} -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -#[SomeAttribute(firstName: ExistingClass::class)] -class SomeClass -{ -} -CODE_SAMPLE - ), - ]); - } - - private function isClassConstFetch(Expr $expr): bool - { - if (! $expr instanceof ClassConstFetch) { - return false; - } - - if (! $expr->name instanceof Identifier) { - return false; - } - - return $expr->name->toString() === 'class'; - } -} diff --git a/tests/Rules/CheckAttributteArgumentClassExistsRule/CheckAttributteArgumentClassExistsRuleTest.php b/tests/Rules/CheckAttributteArgumentClassExistsRule/CheckAttributteArgumentClassExistsRuleTest.php deleted file mode 100644 index 392169a9..00000000 --- a/tests/Rules/CheckAttributteArgumentClassExistsRule/CheckAttributteArgumentClassExistsRuleTest.php +++ /dev/null @@ -1,45 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipExistingClassAttributeArgument.php', []]; - - yield [__DIR__ . '/Fixture/SomeClassWithAttributeArgumentMissingClass.php', [ - [CheckAttributteArgumentClassExistsRule::ERROR_MESSAGE, 9], - ]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(CheckAttributteArgumentClassExistsRule::class); - } -} diff --git a/tests/Rules/CheckAttributteArgumentClassExistsRule/Fixture/SkipExistingClassAttributeArgument.php b/tests/Rules/CheckAttributteArgumentClassExistsRule/Fixture/SkipExistingClassAttributeArgument.php deleted file mode 100644 index ee497f33..00000000 --- a/tests/Rules/CheckAttributteArgumentClassExistsRule/Fixture/SkipExistingClassAttributeArgument.php +++ /dev/null @@ -1,13 +0,0 @@ -