-
-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DeadCode] Add early return check to RemoveUnusedNonEmptyArrayBeforeForeachRector #3611
Merged
Merged
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e1285fd
[DeadCode] Add early return check to RemoveUnusedNonEmptyArrayBeforeF…
TomasVotruba 3416bc4
skip edge case
TomasVotruba 800b2a5
Add fixture multi if -> foreach
samsonasik 560c1dd
Add the patch by loop jump to key recursive
samsonasik 5634f96
[ci-review] Rector Rectify
actions-user a601090
clean up skip config
samsonasik bd2ea41
Revert clean up skip config
samsonasik 36f20f1
Revert [ci-review] Rector Rectify
samsonasik 662612b
Revert Add the patch by loop jump to key recursive
samsonasik 1cefab4
Revert Add fixture multi if -> foreach
samsonasik 1fdc478
add failing fixture throw inside empty
samsonasik de215f8
Add patch ensure if only return with no expr
samsonasik 833fd62
add fixture for multi ifs and fixtures
samsonasik 55f6663
Fixed :tada:
samsonasik 48e6e63
rename fixture
samsonasik af6f370
skip has return with value inside foreach
samsonasik 0db3625
rename fixture
samsonasik bd8b9f9
optimize, allow multi if check, but last only
samsonasik e23e2e3
temporary pin phpunit to 10.0.19 due to make error on paratest
samsonasik 5b306c2
Fix phpstan
samsonasik 6091029
use paratest 7.1.3
samsonasik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 35 additions & 0 deletions
35
...ctor/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector/Fixture/if_check_with_empty.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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
final class IfCheckWithEmpty | ||
{ | ||
public function run(array $items) | ||
{ | ||
if (empty($items)) { | ||
return; | ||
} | ||
|
||
foreach ($items as $item) { | ||
echo $item; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
final class IfCheckWithEmpty | ||
{ | ||
public function run(array $items) | ||
{ | ||
foreach ($items as $item) { | ||
echo $item; | ||
} | ||
} | ||
} | ||
|
||
?> |
35 changes: 35 additions & 0 deletions
35
...nusedNonEmptyArrayBeforeForeachRector/Fixture/if_with_return_value_inside_foreach.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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
final class IfWithReturnValueInsideForeach | ||
{ | ||
public function run(array $items) | ||
{ | ||
if (empty($items)) { | ||
return; | ||
} | ||
|
||
foreach ($items as $item) { | ||
return 1; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
final class IfWithReturnValueInsideForeach | ||
{ | ||
public function run(array $items) | ||
{ | ||
foreach ($items as $item) { | ||
return 1; | ||
} | ||
} | ||
} | ||
|
||
?> |
19 changes: 19 additions & 0 deletions
19
...moveUnusedNonEmptyArrayBeforeForeachRector/Fixture/skip_if_check_throw_with_empty.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\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
use Exception; | ||
|
||
final class SkipIfCheckThrowWithEmpty | ||
{ | ||
public function run(array $items) | ||
{ | ||
if (empty($items)) { | ||
throw new Exception('items must not be empty'); | ||
} | ||
|
||
foreach ($items as $item) { | ||
echo $item; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...moveUnusedNonEmptyArrayBeforeForeachRector/Fixture/skip_multi_if_check_with_empty.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,25 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
final class SkipMultiIfCheckWithEmpty | ||
{ | ||
public function run(array $items, array $items2) | ||
{ | ||
if (empty($items)) { | ||
return; | ||
} | ||
|
||
foreach ($items as $item) { | ||
echo $item; | ||
} | ||
|
||
if (empty($items2)) { | ||
return; | ||
} | ||
|
||
foreach ($items2 as $item2) { | ||
echo $item2; | ||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems it can be optimized by only get
$stmtsAware->stms[$lastKey - 1]
and$stmtsAware->stms[$lastKey]
, that make loop is not neededThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optimized, also allow multi if -> foreach which actually ok, with only remove last if bd8b9f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New phpunit https://github.com/sebastianbergmann/phpunit/releases/tag/10.1.0 seems cause error on paratest, the handling is still on progress paratestphp/paratest#752
I will set phpunit to 10.0.19 temporary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I temporary set phpunit to 10.0.19 e23e2e3 while wait for paratest handling for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paratest 7.1.3 just released https://github.com/paratestphp/paratest/releases/tag/v7.1.3, let's try 6091029