Skip to content

Commit

Permalink
Do not report constructor unused parameter if class is an Attribute c…
Browse files Browse the repository at this point in the history
…lass
  • Loading branch information
carlos-granados committed Jan 10, 2025
1 parent eb0e0bc commit 5c063f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Rules/Classes/UnusedConstructorParametersRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public function processNode(Node $node, Scope $scope): array
if (count($originalNode->params) === 0) {
return [];
}
if ($node->getClassReflection()->isAttributeClass()) {
return [];
}

$message = sprintf(
'Constructor of class %s has an unused parameter $%%s.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function testBug1917(): void
$this->analyse([__DIR__ . '/data/bug-1917.php'], []);
}

public function testBug7165(): void
{
$this->analyse([__DIR__ . '/data/bug-7165.php'], []);
}

public function testBug10865(): void
{
$this->analyse([__DIR__ . '/data/bug-10865.php'], []);
Expand Down
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Classes/data/bug-7165.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1); // lint >= 8.0

namespace Bug7165;

#[\Attribute]
class MyAttribute
{
public function __construct(string $name)
{
}
}

0 comments on commit 5c063f6

Please sign in to comment.