Skip to content

Commit 0b750a9

Browse files
committed
work in progress.. crashing atm
1 parent 65a5889 commit 0b750a9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Rules/Traits/TraitAttributesRule.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
use Attribute;
66
use PhpParser\Node;
7+
use PHPStan\Analyser\MutatingScope;
78
use PHPStan\Analyser\Scope;
89
use PHPStan\Reflection\ReflectionProvider;
910
use PHPStan\Rules\AttributesCheck;
1011
use PHPStan\Rules\Rule;
1112
use PHPStan\Rules\RuleErrorBuilder;
13+
use PHPStan\ShouldNotHappenException;
1214
use function count;
1315

1416
/**
@@ -39,6 +41,12 @@ public function processNode(Node $node, Scope $scope): array
3941
if (!$this->reflectionProvider->hasClass($traitName->toString())) {
4042
return [];
4143
}
44+
$classReflection = $this->reflectionProvider->getClass($traitName->toString());
45+
46+
if (!$scope instanceof MutatingScope) {
47+
throw new ShouldNotHappenException();
48+
}
49+
$scope = $scope->enterTrait($classReflection);
4250

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

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

0 commit comments

Comments
 (0)