-
-
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.
[CodeQuality][EarlyReturn] Handle ChangeOrIfReturnToEarlyReturnRector…
… + ChangeAndIfToEarlyReturnRector + DateTimeToDateTimeInterfaceRector (#794)
- Loading branch information
1 parent
9fee4dd
commit 3e5ecbc
Showing
5 changed files
with
116 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
59 changes: 59 additions & 0 deletions
59
tests/Issues/IssueEarlyReturnAndOrDatetime/Fixture/and_next_or.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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\IssueEarlyReturnAndOrDatetime\Fixture; | ||
|
||
class AndNextOr | ||
{ | ||
public function run($a, $b, $c, $d) | ||
{ | ||
if ($a && $b || $c) { | ||
return null; | ||
} | ||
|
||
$a = 1; | ||
$b = 2; | ||
|
||
if ($b > $a) { | ||
return null; | ||
} | ||
|
||
$d = 1; | ||
|
||
return; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\IssueEarlyReturnAndOrDatetime\Fixture; | ||
|
||
class AndNextOr | ||
{ | ||
public function run($a, $b, $c, $d) | ||
{ | ||
if ($a && $b) { | ||
return null; | ||
} | ||
if ($c) { | ||
return null; | ||
} | ||
$a = 1; | ||
$b = 2; | ||
|
||
if ($b > $a) { | ||
return null; | ||
} | ||
|
||
$d = 1; | ||
|
||
return; | ||
} | ||
} | ||
|
||
?> |
33 changes: 33 additions & 0 deletions
33
tests/Issues/IssueEarlyReturnAndOrDatetime/IssueEarlyReturnAndOrDatetimeTest.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\IssueEarlyReturnAndOrDatetime; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class IssueEarlyReturnAndOrDatetimeTest 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'; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/Issues/IssueEarlyReturnAndOrDatetime/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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\CodeQuality\Rector\ClassMethod\DateTimeToDateTimeInterfaceRector; | ||
use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector; | ||
use Rector\EarlyReturn\Rector\If_\ChangeOrIfReturnToEarlyReturnRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(ChangeOrIfReturnToEarlyReturnRector::class); | ||
$services->set(ChangeAndIfToEarlyReturnRector::class); | ||
$services->set(DateTimeToDateTimeInterfaceRector::class); | ||
}; |