[DeadCode] Rector RemoveDeadConstructorRector should skip private method

This commit is contained in:
Joseph Bielawski 2019-07-19 16:16:30 +02:00
parent 361c9eb832
commit d2923570d2
3 changed files with 22 additions and 1 deletions

View File

@ -53,6 +53,11 @@ CODE_SAMPLE
return null;
}
// Skip private as they lock creating new instances via `new ClassName()`
if ($node->isPrivate()) {
return null;
}
$this->removeNode($node);
return null;

View File

@ -0,0 +1,10 @@
<?php
namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveDeadConstructorRector\Fixture;
class SkipPrivate
{
private function __construct()
{
}
}

View File

@ -9,7 +9,13 @@ final class RemoveDeadConstructorRectorTest extends AbstractRectorTestCase
{
public function test(): void
{
$this->doTestFiles([__DIR__ . '/Fixture/fixture.php.inc', __DIR__ . '/Fixture/skip.php.inc']);
$this->doTestFiles(
[
__DIR__ . '/Fixture/fixture.php.inc',
__DIR__ . '/Fixture/skip.php.inc',
__DIR__ . '/Fixture/skip_private.php.inc',
]
);
}
protected function getRectorClass(): string