Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Rules/Classes/UnusedConstructorParametersRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use function array_values;
use function count;
use function sprintf;
use function strtolower;

/**
* @implements Rule<InClassMethodNode>
Expand All @@ -37,7 +36,7 @@ public function processNode(Node $node, Scope $scope): array
{
$method = $node->getMethodReflection();
$originalNode = $node->getOriginalNode();
if (strtolower($method->getName()) !== '__construct' || $originalNode->stmts === null) {
if (!$method->isConstructor() || $originalNode->stmts === null) {
return [];
}

Expand All @@ -48,6 +47,12 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

foreach ($node->getClassReflection()->getInterfaces() as $interface) {
if ($interface->hasConstructor()) {
return [];
}
}

$message = sprintf(
'Constructor of class %s has an unused parameter $%%s.',
SprintfHelper::escapeFormatString($node->getClassReflection()->getDisplayName()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public function testBug10865(): void
$this->analyse([__DIR__ . '/data/bug-10865.php'], []);
}

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

}
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/Classes/data/bug-11454.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types = 1);

namespace Bug11454;

interface ConstructorInterface
{
public function __construct(string $a);
}

class Foo implements ConstructorInterface {
public function __construct(string $a)
{
}
}
Loading