Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that trait is analysed #226

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/Usages/AttributeUsages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions tests/Usages/AttributeUsagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], []);
}

}
32 changes: 32 additions & 0 deletions tests/src/disallowed/TraitWithAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types = 1);

namespace DebuggingTraits;

#[AttributeClass1]
trait TraitWithAttributes
{

#[AttributeClass2]
private const TRAIT_CONST = true;

#[AttributeClass3]
private $bar;


#[AttributeClass4]
public function traitMethod(
#[AttributeClass5]
bool $param
): void {
}

}


class ClassWithTraitWithAttributes
{

use TraitWithAttributes;

}