From ba29c9a302a596d26cd801cc54c0c370507528a4 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 8 Dec 2023 07:41:42 +0100 Subject: [PATCH] Make sure that trait is analysed --- composer.json | 3 ++ src/Usages/AttributeUsages.php | 1 + tests/Usages/AttributeUsagesTest.php | 5 +++ tests/src/disallowed/TraitWithAttributes.php | 32 ++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 tests/src/disallowed/TraitWithAttributes.php diff --git a/composer.json b/composer.json index b86fdc5..1d08229 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,9 @@ "autoload": { "psr-4": {"Spaze\\PHPStan\\Rules\\Disallowed\\": "src"} }, + "autoload-dev": { + "classmap": ["tests/src"] + }, "scripts": { "lint": "vendor/bin/parallel-lint --colors src/ tests/", "lint-7.x": "vendor/bin/parallel-lint --colors src/ tests/ --exclude tests/src/TypesEverywhere.php --exclude tests/src/disallowed/functionCallsNamedParams.php --exclude tests/src/disallowed-allow/functionCallsNamedParams.php --exclude tests/src/disallowed/attributeUsages.php --exclude tests/src/disallowed-allow/attributeUsages.php", diff --git a/src/Usages/AttributeUsages.php b/src/Usages/AttributeUsages.php index 4515c60..66d4701 100644 --- a/src/Usages/AttributeUsages.php +++ b/src/Usages/AttributeUsages.php @@ -67,6 +67,7 @@ private function addAttrs(array $attributeGroups): void public function processNode(Node $node, Scope $scope): array { + var_dump(get_class($node)); $this->attributes = []; if ($node instanceof ClassLike) { $this->addAttrs(array_values($node->attrGroups)); diff --git a/tests/Usages/AttributeUsagesTest.php b/tests/Usages/AttributeUsagesTest.php index af25218..b2e188d 100644 --- a/tests/Usages/AttributeUsagesTest.php +++ b/tests/Usages/AttributeUsagesTest.php @@ -71,4 +71,9 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/ClassWithAttributesAllow.php'], []); } + public function testTraits(): void + { + $this->analyse([__DIR__ . '/../src/disallowed/TraitWithAttributes.php'], []); + } + } diff --git a/tests/src/disallowed/TraitWithAttributes.php b/tests/src/disallowed/TraitWithAttributes.php new file mode 100644 index 0000000..d8373f8 --- /dev/null +++ b/tests/src/disallowed/TraitWithAttributes.php @@ -0,0 +1,32 @@ +