Skip to content

Commit

Permalink
work in progress.. crashing atm
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Dec 19, 2024
1 parent 65a5889 commit 0b750a9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Rules/Traits/TraitAttributesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use Attribute;
use PhpParser\Node;
use PHPStan\Analyser\MutatingScope;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\AttributesCheck;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\ShouldNotHappenException;
use function count;

/**
Expand Down Expand Up @@ -39,6 +41,12 @@ public function processNode(Node $node, Scope $scope): array
if (!$this->reflectionProvider->hasClass($traitName->toString())) {
return [];
}
$classReflection = $this->reflectionProvider->getClass($traitName->toString());

if (!$scope instanceof MutatingScope) {
throw new ShouldNotHappenException();
}
$scope = $scope->enterTrait($classReflection);

$errors = $this->attributesCheck->check(
$scope,
Expand All @@ -47,7 +55,6 @@ public function processNode(Node $node, Scope $scope): array
'class',
);

$classReflection = $this->reflectionProvider->getClass($traitName->toString());
if (count($classReflection->getNativeReflection()->getAttributes('AllowDynamicProperties')) > 0) {
$errors[] = RuleErrorBuilder::message('Attribute class AllowDynamicProperties cannot be used with trait.')
->identifier('trait.allowDynamicProperties')
Expand Down

0 comments on commit 0b750a9

Please sign in to comment.