-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode][EarlyReturn] Handle RemoveUnusedPrivateMethodRector + Remo…
…veAlwaysElseRector (#807) * added failing test fixture * update * update * Closes #801 Fixes rectorphp/rector#6670 Co-authored-by: Bl00D4NGEL <kuhlesdominik@gmx.de>
- Loading branch information
1 parent
0f9e4f8
commit b1d573e
Showing
5 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tests/Issues/Issue6670/Fixture/do_not_remove_used_class_method.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
?> |
36 changes: 36 additions & 0 deletions
36
tests/Issues/Issue6670/RemoveAlwaysElseAndUnusedPrivateMethodsRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |