Skip to content

Commit cdbed86

Browse files
committed
Private __clone method isn't considered unused
1 parent 8d84146 commit cdbed86

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/Rules/DeadCode/UnusedPrivateMethodRule.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public function processNode(Node $node, Scope $scope): array
4646
if (!$method->isPrivate()) {
4747
continue;
4848
}
49-
if ($constructor !== null && $constructor->getName() === $method->name->toString()) {
49+
$methodName = $method->name->toString();
50+
if ($constructor !== null && $constructor->getName() === $methodName) {
51+
continue;
52+
}
53+
if (strtolower($methodName) === '__clone') {
5054
continue;
5155
}
5256
$methods[$method->name->toString()] = $method;

tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ public function testRule(): void
4242
]);
4343
}
4444

45+
public function testBug3630(): void
46+
{
47+
$this->analyse([__DIR__ . '/data/bug-3630.php'], []);
48+
}
49+
4550
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Bug3630;
4+
5+
class HelloWorld
6+
{
7+
private function __clone()
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)