Skip to content

Commit 812f20b

Browse files
authored
[DeadCode] Skip non-public __clone() method on RemoveEmptyClassMethodRector (#7187)
1 parent 59b1488 commit 812f20b

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Fixture;
4+
5+
class SkipPrivateClone
6+
{
7+
private function __clone()
8+
{
9+
}
10+
}

rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ private function shouldSkipClassMethod(Class_ $class, ClassMethod $classMethod):
162162
return $class->extends instanceof FullyQualified;
163163
}
164164

165+
if ($this->isName($classMethod, MethodName::CLONE)) {
166+
return ! $classMethod->isPublic();
167+
}
168+
165169
return $this->isName($classMethod, MethodName::INVOKE);
166170
}
167171

0 commit comments

Comments
 (0)