Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function refactor(Node $node): ?Node
return null;
}

// Skip private as they lock creating new instances via `new ClassName()`
if ($node->isPrivate()) {
return null;
}

$this->removeNode($node);

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveDeadConstructorRector\Fixture;

class SkipPrivate
{
private function __construct()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down