Skip to content

Commit f2bf43c

Browse files
carlos-granadosondrejmirtes
authored andcommitted
Do not report constructor unused parameter if class is an Attribute class
1 parent 73d7b88 commit f2bf43c

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/Rules/Classes/UnusedConstructorParametersRule.php

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function processNode(Node $node, Scope $scope): array
4444
if (count($originalNode->params) === 0) {
4545
return [];
4646
}
47+
if ($node->getClassReflection()->isAttributeClass()) {
48+
return [];
49+
}
4750

4851
$message = sprintf(
4952
'Constructor of class %s has an unused parameter $%%s.',

tests/PHPStan/Rules/Classes/UnusedConstructorParametersRuleTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public function testBug1917(): void
6161
$this->analyse([__DIR__ . '/data/bug-1917.php'], []);
6262
}
6363

64+
public function testBug7165(): void
65+
{
66+
$this->analyse([__DIR__ . '/data/bug-7165.php'], []);
67+
}
68+
6469
public function testBug10865(): void
6570
{
6671
$this->analyse([__DIR__ . '/data/bug-10865.php'], []);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types=1); // lint >= 8.0
2+
3+
namespace Bug7165;
4+
5+
#[\Attribute]
6+
class MyAttribute
7+
{
8+
public function __construct(string $name)
9+
{
10+
}
11+
}
12+

0 commit comments

Comments
 (0)