Skip to content

[DeadCode] RemoveDeadConstructorRector should not remove private construct #1750

@stloyd

Description

@stloyd
Subject Details
PHP version any
Full Command vendor/bin/rector process /src --set dead-code

Current Behaviour

Rector Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector removes also private method, which should not be touched as it's done for purpose to not allow calls: new SomeClass().

-    private function __construct()
-    {
-    }
-
     public static function someMethod(): bool
     {

Minimal PHP Code Causing Issue

<?php

class SomeClass
{
     private function __construct()
     {
     }

     public static function forExampleFactoryMethod()
     {
         return new self();
     }
}

Expected Behaviour

No changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions