mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-15 15:42:22 +00:00
[DeadCode][EarlyReturn] Handle RemoveUnusedPrivateMethodRector + RemoveAlwaysElseRector (#807)
* added failing test fixture * update * update * Closes #801 Fixes https://github.com/rectorphp/rector/issues/6670 Co-authored-by: Bl00D4NGEL <kuhlesdominik@gmx.de>
This commit is contained in:
parent
0f9e4f8360
commit
b1d573e8b5
|
@ -78,6 +78,10 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
if ($this->nodesToAddCollector->isActive()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->removeNode($node);
|
||||
|
||||
return $node;
|
||||
|
|
|
@ -122,7 +122,7 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
|
|||
*/
|
||||
private $previousAppliedClass;
|
||||
|
||||
private NodesToAddCollector $nodesToAddCollector;
|
||||
protected NodesToAddCollector $nodesToAddCollector;
|
||||
|
||||
private CurrentFileProvider $currentFileProvider;
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\Issues\Issue6670\Fixture;
|
||||
|
||||
final class DoNotRemoveUsedClassMethod
|
||||
{
|
||||
public function doSomething(): int
|
||||
{
|
||||
if (true === false) {
|
||||
return -1;
|
||||
} else {
|
||||
return $this->notUnused();
|
||||
}
|
||||
}
|
||||
|
||||
private function notUnused(): int
|
||||
{
|
||||
// This is some code that is very important
|
||||
}
|
||||
}
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\Issues\Issue6670\Fixture;
|
||||
|
||||
final class DoNotRemoveUsedClassMethod
|
||||
{
|
||||
public function doSomething(): int
|
||||
{
|
||||
if (true === false) {
|
||||
return -1;
|
||||
}
|
||||
return $this->notUnused();
|
||||
}
|
||||
|
||||
private function notUnused(): int
|
||||
{
|
||||
// This is some code that is very important
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Issues\Issue6670;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
/**
|
||||
* @see https://github.com/rectorphp/rector/issues/6670
|
||||
*/
|
||||
final class RemoveAlwaysElseAndUnusedPrivateMethodsRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
13
tests/Issues/Issue6670/config/configured_rule.php
Normal file
13
tests/Issues/Issue6670/config/configured_rule.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
|
||||
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(RemoveUnusedPrivateMethodRector::class);
|
||||
$services->set(RemoveAlwaysElseRector::class);
|
||||
};
|
Loading…
Reference in New Issue
Block a user