Skip to content

Commit 5cfe075

Browse files
committed
AttributeReflectionFromNodeRuleTest - test parameter attributes
1 parent a387fa3 commit 5cfe075

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tests/PHPStan/Reflection/AttributeReflectionFromNodeRuleTest.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ public function processNode(Node $node, Scope $scope): array
5151
$parts[] = sprintf('#[%s(%s)]', $attribute->getName(), implode(', ', $args));
5252
}
5353

54+
foreach ($reflection->getParameters() as $parameter) {
55+
$parameterAttributes = [];
56+
foreach ($parameter->getAttributes() as $parameterAttribute) {
57+
$parameterArgs = [];
58+
foreach ($parameterAttribute->getArgumentTypes() as $argName => $argType) {
59+
$parameterArgs[] = sprintf('%s: %s', $argName, $argType->describe(VerbosityLevel::precise()));
60+
}
61+
$parameterAttributes[] = sprintf('#[%s(%s)]', $parameterAttribute->getName(), implode(', ', $parameterArgs));
62+
}
63+
64+
if (count($parameterAttributes) === 0) {
65+
continue;
66+
}
67+
68+
$parts[] = sprintf('$%s: %s', $parameter->getName(), implode(', ', $parameterAttributes));
69+
}
70+
5471
if (count($parts) === 0) {
5572
return [];
5673
}
@@ -71,7 +88,7 @@ public function testRule(): void
7188

7289
$this->analyse([__DIR__ . '/data/attribute-reflection.php'], [
7390
[
74-
'#[AttributeReflectionTest\MyAttr(one: 7, two: 8)]',
91+
'#[AttributeReflectionTest\MyAttr(one: 7, two: 8)], $test: #[AttributeReflectionTest\MyAttr(one: 9, two: 10)]',
7592
28,
7693
],
7794
[

0 commit comments

Comments
 (0)