Skip to content

Commit

Permalink
Private __clone method isn't considered unused
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 2, 2020
1 parent 8d84146 commit cdbed86
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Rules/DeadCode/UnusedPrivateMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public function testRule(): void
]);
}

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

}
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-3630.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Bug3630;

class HelloWorld
{
private function __clone()
{
}
}

0 comments on commit cdbed86

Please sign in to comment.