-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode] Register more Stmt Nodes on RemoveUnreachableStatementRect…
…or (#2140) * [DeadCode] Register more Stmt Nodes on RemoveUnreachableStatementRector * add try * final touch: exclude ArrowFunction FunctionLike as only 1 stmt * [ci-review] Rector Rectify Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
365b289
commit 469f0ee
Showing
9 changed files
with
334 additions
and
3 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/some_case.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,34 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
class SomeCase | ||
{ | ||
public function run() | ||
{ | ||
switch ($a) { | ||
case 'a': | ||
return 'A'; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
class SomeCase | ||
{ | ||
public function run() | ||
{ | ||
switch ($a) { | ||
case 'a': | ||
return 'A'; | ||
} | ||
} | ||
} | ||
|
||
?> |
42 changes: 42 additions & 0 deletions
42
rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/some_catch.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\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
use RuntimeException; | ||
|
||
class SomeCatch | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
|
||
} catch (Exception $e) { | ||
throw new RuntimeException($e->getMesssage()); | ||
echo 'test'; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
use RuntimeException; | ||
|
||
class SomeCatch | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
|
||
} catch (Exception $e) { | ||
throw new RuntimeException($e->getMesssage()); | ||
} | ||
} | ||
} | ||
|
||
?> |
38 changes: 38 additions & 0 deletions
38
rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/some_do.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,38 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
|
||
class SomeDo | ||
{ | ||
public function run() | ||
{ | ||
$i = 1; | ||
do { | ||
throw new Exception(); | ||
echo 'test'; | ||
} while (++$i < 10); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
|
||
class SomeDo | ||
{ | ||
public function run() | ||
{ | ||
$i = 1; | ||
do { | ||
throw new Exception(); | ||
} while (++$i < 10); | ||
} | ||
} | ||
|
||
?> |
40 changes: 40 additions & 0 deletions
40
...-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/some_else_if.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,40 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
|
||
class SomeElseIf | ||
{ | ||
public function run() | ||
{ | ||
if (rand(0, 1)) { | ||
|
||
} elseif (rand(0, 1)) { | ||
throw new Exception(); | ||
echo 'test'; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
|
||
class SomeElseIf | ||
{ | ||
public function run() | ||
{ | ||
if (rand(0, 1)) { | ||
|
||
} elseif (rand(0, 1)) { | ||
throw new Exception(); | ||
} | ||
} | ||
} | ||
|
||
?> |
42 changes: 42 additions & 0 deletions
42
...-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/some_finally.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\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
use RuntimeException; | ||
|
||
class SomeFinally | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
|
||
} finally { | ||
throw new RuntimeException(); | ||
echo 'test'; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
use RuntimeException; | ||
|
||
class SomeFinally | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
|
||
} finally { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
} | ||
|
||
?> |
36 changes: 36 additions & 0 deletions
36
rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/some_for.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,36 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
|
||
class SomeFor | ||
{ | ||
public function run() | ||
{ | ||
for ($i = 1; $i<10;++$i) { | ||
throw new Exception(); | ||
echo 'test'; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
|
||
class SomeFor | ||
{ | ||
public function run() | ||
{ | ||
for ($i = 1; $i<10;++$i) { | ||
throw new Exception(); | ||
} | ||
} | ||
} | ||
|
||
?> |
40 changes: 40 additions & 0 deletions
40
rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/some_try.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,40 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use RuntimeException; | ||
|
||
class SomeTry | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
throw new RuntimeException(); | ||
echo 'test'; | ||
} finally { | ||
|
||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use RuntimeException; | ||
|
||
class SomeTry | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
throw new RuntimeException(); | ||
} finally { | ||
|
||
} | ||
} | ||
} | ||
|
||
?> |
36 changes: 36 additions & 0 deletions
36
rules-tests/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector/Fixture/some_while.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,36 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
|
||
class SomeWhile | ||
{ | ||
public function run() | ||
{ | ||
while (++$i < 10) { | ||
throw new Exception(); | ||
echo 'test'; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector\Fixture; | ||
|
||
use Exception; | ||
|
||
class SomeWhile | ||
{ | ||
public function run() | ||
{ | ||
while (++$i < 10) { | ||
throw new 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