-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodeQuality] Allow transform return; to return null; when there is o…
…ther return with Expr on ExplicitReturnNullRector (#5761) * [CodeQuality] Allow transform return; to return null; when there is other return with Expr on ExplicitReturnNullRector * [ci-review] Rector Rectify * more test * [ci-review] Rector Rectify * rename fixture * update docblock example * dont traverse children * fix return * more fixture --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
cae0691
commit 97e2433
Showing
4 changed files
with
126 additions
and
21 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...tor/ClassMethod/ExplicitReturnNullRector/Fixture/return_no_value_and_return_value.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,46 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class ReturnNoValueAndReturnValue | ||
{ | ||
/** | ||
* @return int|void | ||
*/ | ||
public function run(int $number) | ||
{ | ||
if ($number > 50) { | ||
return; | ||
} | ||
|
||
if ($number < 50) { | ||
return 100; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
final class ReturnNoValueAndReturnValue | ||
{ | ||
/** | ||
* @return int|null | ||
*/ | ||
public function run(int $number) | ||
{ | ||
if ($number > 50) { | ||
return null; | ||
} | ||
|
||
if ($number < 50) { | ||
return 100; | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
?> |
45 changes: 45 additions & 0 deletions
45
...or/ClassMethod/ExplicitReturnNullRector/Fixture/return_no_value_and_return_value2.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,45 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
final class ReturnNoValueAndReturnValue2 | ||
{ | ||
/** | ||
* @return stdClass|void | ||
*/ | ||
public function add() | ||
{ | ||
if ('POST' !== $_SERVER['REQUEST_METHOD']) { | ||
return; | ||
} | ||
|
||
return new stdClass(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
final class ReturnNoValueAndReturnValue2 | ||
{ | ||
/** | ||
* @return stdClass|null | ||
*/ | ||
public function add() | ||
{ | ||
if ('POST' !== $_SERVER['REQUEST_METHOD']) { | ||
return null; | ||
} | ||
|
||
return new stdClass(); | ||
} | ||
} | ||
|
||
?> |
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