diff --git a/src/Rules/DeadCode/UnusedPrivateMethodRule.php b/src/Rules/DeadCode/UnusedPrivateMethodRule.php index 74ed6bda66..f83c3cf212 100644 --- a/src/Rules/DeadCode/UnusedPrivateMethodRule.php +++ b/src/Rules/DeadCode/UnusedPrivateMethodRule.php @@ -46,7 +46,11 @@ public function processNode(Node $node, Scope $scope): array if (!$method->isPrivate()) { continue; } - if ($constructor !== null && $constructor->getName() === $method->name->toString()) { + $methodName = $method->name->toString(); + if ($constructor !== null && $constructor->getName() === $methodName) { + continue; + } + if (strtolower($methodName) === '__clone') { continue; } $methods[$method->name->toString()] = $method; diff --git a/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php b/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php index 24c262ed1c..8415e70f46 100644 --- a/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php @@ -42,4 +42,9 @@ public function testRule(): void ]); } + public function testBug3630(): void + { + $this->analyse([__DIR__ . '/data/bug-3630.php'], []); + } + } diff --git a/tests/PHPStan/Rules/DeadCode/data/bug-3630.php b/tests/PHPStan/Rules/DeadCode/data/bug-3630.php new file mode 100644 index 0000000000..602dbe49a7 --- /dev/null +++ b/tests/PHPStan/Rules/DeadCode/data/bug-3630.php @@ -0,0 +1,10 @@ +