|
9 | 9 | use PHPStan\Rules\RuleErrorBuilder;
|
10 | 10 | use PHPStan\Type\ObjectType;
|
11 | 11 | use function array_keys;
|
12 |
| -use function count; |
13 | 12 | use function in_array;
|
14 | 13 | use function sprintf;
|
15 | 14 | use function str_starts_with;
|
@@ -41,38 +40,40 @@ public function processNode(Node $node, Scope $scope): array
|
41 | 40 | if (!isset($args[0])) {
|
42 | 41 | return [];
|
43 | 42 | }
|
| 43 | + |
| 44 | + $messages = []; |
44 | 45 | $argType = $scope->getType($args[0]->value);
|
45 |
| - if (count($argType->getConstantStrings()) !== 1) { |
46 |
| - return []; |
47 |
| - } |
48 |
| - $argValue = $argType->getConstantScalarValues()[0]; |
49 |
| - if (!in_array($argValue, ['parent', 'previous', 'next'], true)) { |
50 |
| - return []; |
51 |
| - } |
52 |
| - if (!$scope->isInClass()) { |
53 |
| - return []; |
54 |
| - } |
| 46 | + foreach ($argType->getConstantStrings() as $constantString) { |
| 47 | + $argValue = $constantString->getValue(); |
| 48 | + if (!in_array($argValue, ['parent', 'previous', 'next'], true)) { |
| 49 | + continue; |
| 50 | + } |
55 | 51 |
|
56 |
| - $classReflection = $scope->getClassReflection(); |
57 |
| - $hasPhpStanInterface = false; |
58 |
| - foreach (array_keys($classReflection->getInterfaces()) as $interfaceName) { |
59 |
| - if (!str_starts_with($interfaceName, 'PHPStan\\')) { |
| 52 | + if (!$scope->isInClass()) { |
60 | 53 | continue;
|
61 | 54 | }
|
62 | 55 |
|
63 |
| - $hasPhpStanInterface = true; |
64 |
| - } |
| 56 | + $classReflection = $scope->getClassReflection(); |
| 57 | + $hasPhpStanInterface = false; |
| 58 | + foreach (array_keys($classReflection->getInterfaces()) as $interfaceName) { |
| 59 | + if (!str_starts_with($interfaceName, 'PHPStan\\')) { |
| 60 | + continue; |
| 61 | + } |
65 | 62 |
|
66 |
| - if (!$hasPhpStanInterface) { |
67 |
| - return []; |
68 |
| - } |
| 63 | + $hasPhpStanInterface = true; |
| 64 | + } |
69 | 65 |
|
70 |
| - return [ |
71 |
| - RuleErrorBuilder::message(sprintf('Node attribute \'%s\' is no longer available.', $argValue)) |
| 66 | + if (!$hasPhpStanInterface) { |
| 67 | + continue; |
| 68 | + } |
| 69 | + |
| 70 | + $messages[] = RuleErrorBuilder::message(sprintf('Node attribute \'%s\' is no longer available.', $argValue)) |
72 | 71 | ->identifier('phpParser.nodeConnectingAttribute')
|
73 | 72 | ->tip('See: https://phpstan.org/blog/preprocessing-ast-for-custom-rules')
|
74 |
| - ->build(), |
75 |
| - ]; |
| 73 | + ->build(); |
| 74 | + } |
| 75 | + |
| 76 | + return $messages; |
76 | 77 | }
|
77 | 78 |
|
78 | 79 | }
|
0 commit comments