|
3 | 3 | namespace PHPStan\Rules\Properties;
|
4 | 4 |
|
5 | 5 | use PhpParser\Node\Expr\PropertyFetch;
|
| 6 | +use PhpParser\Node\Identifier; |
6 | 7 | use PHPStan\Analyser\Scope;
|
7 | 8 | use PHPStan\Reflection\ReflectionProvider;
|
| 9 | +use PHPStan\Rules\RuleError; |
8 | 10 | use PHPStan\Rules\RuleErrorBuilder;
|
9 | 11 | use PHPStan\Rules\RuleLevelHelper;
|
| 12 | +use PHPStan\Type\Constant\ConstantStringType; |
10 | 13 | use PHPStan\Type\ErrorType;
|
11 | 14 | use PHPStan\Type\Type;
|
| 15 | +use PHPStan\Type\TypeUtils; |
12 | 16 | use PHPStan\Type\VerbosityLevel;
|
13 | 17 |
|
14 | 18 | /**
|
@@ -41,11 +45,30 @@ public function getNodeType(): string
|
41 | 45 |
|
42 | 46 | public function processNode(\PhpParser\Node $node, Scope $scope): array
|
43 | 47 | {
|
44 |
| - if (!$node->name instanceof \PhpParser\Node\Identifier) { |
45 |
| - return []; |
| 48 | + if ($node->name instanceof Identifier) { |
| 49 | + $names = [$node->name->name]; |
| 50 | + } else { |
| 51 | + $names = array_map(static function (ConstantStringType $type): string { |
| 52 | + return $type->getValue(); |
| 53 | + }, TypeUtils::getConstantStrings($scope->getType($node->name))); |
| 54 | + } |
| 55 | + |
| 56 | + $errors = []; |
| 57 | + foreach ($names as $name) { |
| 58 | + $errors = array_merge($errors, $this->processSingleProperty($scope, $node, $name)); |
46 | 59 | }
|
47 | 60 |
|
48 |
| - $name = $node->name->name; |
| 61 | + return $errors; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @param Scope $scope |
| 66 | + * @param PropertyFetch $node |
| 67 | + * @param string $name |
| 68 | + * @return RuleError[] |
| 69 | + */ |
| 70 | + private function processSingleProperty(Scope $scope, PropertyFetch $node, string $name): array |
| 71 | + { |
49 | 72 | $typeResult = $this->ruleLevelHelper->findTypeToCheck(
|
50 | 73 | $scope,
|
51 | 74 | $node->var,
|
|
0 commit comments