-
-
Notifications
You must be signed in to change notification settings - Fork 440
[Php84] Allow on return on ForeachToArrayAnyRector #7119
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3c73144
Add ForeachWithReturnToArrayAnyRector
Orest-Divintari f73ddec
fix
Orest-Divintari c415066
Fix
Orest-Divintari 1ac118a
Fix
Orest-Divintari 5f3b220
fix
Orest-Divintari f74e691
Merge remote-tracking branch 'upstream/main'
Orest-Divintari fe6a6de
Combine array any patterns
Orest-Divintari 876cf12
Delete separate array any rules
Orest-Divintari fe81ee5
Rename ArrayAny rule
Orest-Divintari f14d497
delete test
Orest-Divintari 89d6ebb
rename tests
Orest-Divintari 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 hidden or 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 |
|---|---|---|
|
|
@@ -68,4 +68,4 @@ class BasicUsage | |
| } | ||
| } | ||
|
|
||
| ?> | ||
| ?> | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -16,4 +16,4 @@ class SkipMultipleStatements | |
| } | ||
| return $found; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -15,4 +15,4 @@ class SkipNoBooleanInitialization | |
| } | ||
| return $found; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -14,4 +14,4 @@ class SkipNoBreak | |
| } | ||
| return $found; | ||
| } | ||
| } | ||
| } | ||
File renamed without changes.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -20,4 +20,4 @@ class SkipVariableReUseAfterForeach | |
|
|
||
| return $found; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -32,4 +32,4 @@ class WithKey | |
| } | ||
| } | ||
|
|
||
| ?> | ||
| ?> | ||
60 changes: 60 additions & 0 deletions
60
...ts/Php84/Rector/Foreach_/ForeachToArrayAnyRector/Fixture/early_return_basic_usage.php.inc
This file contains hidden or 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,60 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php84\Rector\Foreach_\ForeachToArrayAnyRector\Fixture; | ||
|
|
||
| class BasicUsage | ||
| { | ||
| public function checkAnimal(array $animals) | ||
| { | ||
| foreach ($animals as $animal) { | ||
| if (str_starts_with($animal, 'c')) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public function checkNumber(array $numbers) | ||
| { | ||
| foreach ($numbers as $number) { | ||
| if ($number > 10) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public function checkWithKey(array $items) | ||
| { | ||
| foreach ($items as $key => $value) { | ||
| if ($value === 'target') { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php84\Rector\Foreach_\ForeachToArrayAnyRector\Fixture; | ||
|
|
||
| class BasicUsage | ||
| { | ||
| public function checkAnimal(array $animals) | ||
| { | ||
| return array_any($animals, fn($animal) => str_starts_with($animal, 'c')); | ||
| } | ||
|
|
||
| public function checkNumber(array $numbers) | ||
| { | ||
| return array_any($numbers, fn($number) => $number > 10); | ||
| } | ||
|
|
||
| public function checkWithKey(array $items) | ||
| { | ||
| return array_any($items, fn($value) => $value === 'target'); | ||
| } | ||
| } | ||
| ?> |
15 changes: 15 additions & 0 deletions
15
...r/Foreach_/ForeachToArrayAnyRector/Fixture/early_return_skip_missing_return_false.php.inc
This file contains hidden or 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\Php84\Rector\Foreach_\ForeachToArrayAnyRector\Fixture; | ||
|
|
||
| class SkipMultipleStatements | ||
| { | ||
| public function run(array $animals) | ||
| { | ||
| foreach ($animals as $animal) { | ||
| if (str_starts_with($animal, 'c')) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...reachToArrayAnyRector/Fixture/early_return_skip_multiple_statements_after_foreach.php.inc
This file contains hidden or 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\Php84\Rector\Foreach_\ForeachToArrayAnyRector\Fixture; | ||
|
|
||
| class SkipMultipleStatements | ||
| { | ||
| public function run(array $animals) | ||
| { | ||
| foreach ($animals as $animal) { | ||
| if (str_starts_with($animal, 'c')) { | ||
| return true; | ||
| } | ||
| } | ||
| echo 'ok'; | ||
| return false; | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...oArrayAnyRector/Fixture/early_return_skip_multiple_statements_within_if_statement.php.inc
This file contains hidden or 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\Php84\Rector\Foreach_\ForeachToArrayAnyRector\Fixture; | ||
|
|
||
| class SkipMultipleStatements | ||
| { | ||
| public function run(array $animals) | ||
| { | ||
| foreach ($animals as $animal) { | ||
| if (str_starts_with($animal, 'c')) { | ||
| echo 'Found: ' . $animal; | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...r/Foreach_/ForeachToArrayAnyRector/Fixture/early_return_skip_nested_if_statements.php.inc
This file contains hidden or 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,18 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php84\Rector\Foreach_\ForeachToArrayAnyRector\Fixture; | ||
|
|
||
| class SkipMultipleStatements | ||
| { | ||
| public function run(array $animals) | ||
| { | ||
| foreach ($animals as $animal) { | ||
| if(str_starts_with($animal, 'foo')) { | ||
| if (str_starts_with($animal, 'c')) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
...Php84/Rector/Foreach_/ForeachToArrayAnyRector/Fixture/early_return_skip_non_array.php.inc
This file contains hidden or 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,16 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php84\Rector\Foreach_\ForeachToArrayAnyRector\Fixture; | ||
|
|
||
| class SkipNonArray | ||
| { | ||
| public function checkAnimal(\ArrayIterator $animals) | ||
| { | ||
| foreach ($animals as $animal) { | ||
| if (str_starts_with($animal, 'c')) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
...oArrayAnyRector/Fixture/early_return_skip_unexpected_early_return_other_than_true.php.inc
This file contains hidden or 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,16 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php84\Rector\Foreach_\ForeachToArrayAnyRector\Fixture; | ||
|
|
||
| class SkipMultipleStatements | ||
| { | ||
| public function run(array $animals) | ||
| { | ||
| foreach ($animals as $animal) { | ||
| if (str_starts_with($animal, 'c')) { | ||
| return 'ok'; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...tests/Php84/Rector/Foreach_/ForeachToArrayAnyRector/Fixture/early_return_with_key.php.inc
This file contains hidden or 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,32 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php84\Rector\Foreach_\ForeachToArrayAnyRector\Fixture; | ||
|
|
||
| class WithKey | ||
| { | ||
| public function checkAnimal(array $animals) | ||
| { | ||
| foreach ($animals as $key => $animal) { | ||
| if (str_starts_with($animal, 'c') && $key === 1) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php84\Rector\Foreach_\ForeachToArrayAnyRector\Fixture; | ||
|
|
||
| class WithKey | ||
| { | ||
| public function checkAnimal(array $animals) | ||
| { | ||
| return array_any($animals, fn($animal, $key) => str_starts_with($animal, 'c') && $key === 1); | ||
| } | ||
| } | ||
|
|
||
| ?> |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.