-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodeQuality] Skip if else return on ExplicitReturnNullRector (#5755)
* [CodeQuality] Skip if else return on ExplicitReturnNullRector * Fix * fix ci * add in try catch * Fix * more fixture * try catch check * try catch check * Fix * [ci-review] Rector Rectify * if else functionality * more fixture * more fixture --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
b4eb883
commit 32bf5c7
Showing
10 changed files
with
262 additions
and
40 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...od/ExplicitReturnNullRector/Fixture/if_else_return_in_try_catch_finally_no_return.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,48 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class IfElseReturnInTryCatchFinallyNoReturn | ||
{ | ||
public function run(int $number) | ||
{ | ||
if (rand(0, 1)) { | ||
try { | ||
return execute(); | ||
} catch (\Exception $e) { | ||
return 2; | ||
} finally { | ||
echo 'here no return'; | ||
} | ||
} else { | ||
return 2; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class IfElseReturnInTryCatchFinallyNoReturn | ||
{ | ||
public function run(int $number) | ||
{ | ||
if (rand(0, 1)) { | ||
try { | ||
return execute(); | ||
} catch (\Exception $e) { | ||
return 2; | ||
} finally { | ||
echo 'here no return'; | ||
} | ||
} else { | ||
return 2; | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
?> |
40 changes: 40 additions & 0 deletions
40
...tor/ClassMethod/ExplicitReturnNullRector/Fixture/if_elseif_else_partial_no_return.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\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class IfElseIfElsePartialNoReturn | ||
{ | ||
public function run(int $number) | ||
{ | ||
if (rand(0, 1)) { | ||
return 1; | ||
} elseif (rand(0, 1)) { | ||
// no return here | ||
} else { | ||
return 2; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class IfElseIfElsePartialNoReturn | ||
{ | ||
public function run(int $number) | ||
{ | ||
if (rand(0, 1)) { | ||
return 1; | ||
} elseif (rand(0, 1)) { | ||
// no return here | ||
} else { | ||
return 2; | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
?> |
36 changes: 36 additions & 0 deletions
36
...uality/Rector/ClassMethod/ExplicitReturnNullRector/Fixture/if_elseif_without_else.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\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class IfElseifWithoutElse | ||
{ | ||
public function run(int $number) | ||
{ | ||
if (rand(0, 1)) { | ||
return 1; | ||
} elseif (rand(0, 1)) { | ||
return 2; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class IfElseifWithoutElse | ||
{ | ||
public function run(int $number) | ||
{ | ||
if (rand(0, 1)) { | ||
return 1; | ||
} elseif (rand(0, 1)) { | ||
return 2; | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
?> |
15 changes: 15 additions & 0 deletions
15
...deQuality/Rector/ClassMethod/ExplicitReturnNullRector/Fixture/skip_if_else_return.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,15 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class SkipIfElseReturn | ||
{ | ||
public function run(int $number) | ||
{ | ||
if ($number > 50) { | ||
return 'yes'; | ||
} else { | ||
return 100; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...tor/ClassMethod/ExplicitReturnNullRector/Fixture/skip_if_else_return_in_try_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,19 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class SkipIfElseReturnInTryCatch | ||
{ | ||
public function run(int $number) | ||
{ | ||
if (rand(0, 1)) { | ||
try { | ||
return execute(); | ||
} catch (\Exception $e) { | ||
return 2; | ||
} | ||
} else { | ||
return 2; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...sMethod/ExplicitReturnNullRector/Fixture/skip_if_else_return_in_try_catch_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,21 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class SkipIfElseReturnInTryCatchFinally | ||
{ | ||
public function run(int $number) | ||
{ | ||
if (rand(0, 1)) { | ||
try { | ||
return execute(); | ||
} catch (\Exception $e) { | ||
return 2; | ||
} finally { | ||
return 3; | ||
} | ||
} else { | ||
return 2; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...or/ClassMethod/ExplicitReturnNullRector/Fixture/skip_if_elseif_else_always_return.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,17 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class SkipIfElseReturnInTryCatch | ||
{ | ||
public function run(int $number) | ||
{ | ||
if (rand(0, 1)) { | ||
return 1; | ||
} elseif (rand(0, 2)) { | ||
return 3; | ||
} else { | ||
return 2; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.