-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
warn about infinite loop node modification (#51)
- Loading branch information
1 parent
eecf18f
commit a60e3ac
Showing
14 changed files
with
241 additions
and
23 deletions.
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
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
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
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
11 changes: 11 additions & 0 deletions
11
src/Exception/NodeTraverser/InfiniteLoopTraversingException.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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Exception\NodeTraverser; | ||
|
||
use Exception; | ||
|
||
final class InfiniteLoopTraversingException extends Exception | ||
{ | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\BooleanNot\SimplifyDeMorganBinaryRector\Fixture; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr; | ||
|
||
class MultiBinary | ||
{ | ||
public function run(Node $node) | ||
{ | ||
return !($node instanceof Node\Name || $node instanceof Expr\StaticCall || $node instanceof Expr\Array_); | ||
|
||
return !($node instanceof Node\Name || $node instanceof Expr\StaticCall); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\BooleanNot\SimplifyDeMorganBinaryRector\Fixture; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr; | ||
|
||
class MultiBinary | ||
{ | ||
public function run(Node $node) | ||
{ | ||
return !($node instanceof Node\Name || $node instanceof Expr\StaticCall || $node instanceof Expr\Array_); | ||
|
||
return !$node instanceof Node\Name && !$node instanceof Expr\StaticCall; | ||
} | ||
} | ||
|
||
?> |
13 changes: 13 additions & 0 deletions
13
tests/Issues/FixtureInfiniteLoop/some_method_call_infinity.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,13 @@ | ||
<?php | ||
|
||
$dateTime = new DateTime(); | ||
$dateTime->modify('+1'); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
$dateTime = new DateTime(); | ||
$dateTime = $dateTime->modify('+1'); | ||
|
||
?> |
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues; | ||
|
||
use Rector\Core\Exception\NodeTraverser\InfiniteLoopTraversingException; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class InfiniteLoopTest extends AbstractRectorTestCase | ||
{ | ||
public function testException(): void | ||
{ | ||
$this->expectException(InfiniteLoopTraversingException::class); | ||
|
||
$fixtureFileInfo = new SmartFileInfo(__DIR__ . '/FixtureInfiniteLoop/some_method_call_infinity.php.inc'); | ||
$this->doTestFileInfo($fixtureFileInfo); | ||
} | ||
|
||
public function testPass(): void | ||
{ | ||
$fixtureFileInfo = new SmartFileInfo(__DIR__ . '/FixtureInfiniteLoop/de_morgan.php.inc'); | ||
$this->doTestFileInfo($fixtureFileInfo); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/infinite_loop.php'; | ||
} | ||
} |
Oops, something went wrong.