[Php84] Allow on return on ForeachToArrayAnyRector#7119
[Php84] Allow on return on ForeachToArrayAnyRector#7119samsonasik merged 11 commits intorectorphp:mainfrom
Conversation
There is already a rule to convert foreach that contains a break statement with array_any. This new rule adds support for foreach that return early with true
|
On return need to be supported on downgrade rule first, which currently only on Expression The |
|
Actually, you may can improve existing rule |
i can do that sure, i wanted to check with you what is your preference |
|
Would be better to improve downgrade rule first, as we most got issue after downgraded a target code |
|
i haven't managed to set it up locally properly and i can't run tests for some reason when i do
any idea what might be the issue ? @samsonasik |
|
You may need to install gpatch, see troubleshooting note https://github.com/symplify/vendor-patches/?tab=readme-ov-file#troubleshooting |
rules/Php84/Rector/Foreach_/ForeachWithReturnToArrayAnyRector.php
Outdated
Show resolved
Hide resolved
rules/Php84/Rector/Foreach_/ForeachWithReturnToArrayAnyRector.php
Outdated
Show resolved
Hide resolved
rules/Php84/Rector/Foreach_/ForeachWithReturnToArrayAnyRector.php
Outdated
Show resolved
Hide resolved
|
i'll do also the downgrade rule |
|
Downgrade rule already covered for return :) |
|
does it cover also this code ? |
|
Downgrade is cover direct return function, change this: return array_any($animals, fn($animal) => str_starts_with($animal, 'c'));into: $found = false;
foreach ($animals as $animal) {
if (str_starts_with($animal, 'c')) {
$found = true;
break;
}
}
return $found;equivalent code needs exists when upgraded code downgraded, on rector usecase, rector downgraded to php 7.4, that's downgrade rule usage needs after new upgrade feture added, other lib/project that downgrade code after upgraded via rector needs that as well. |
...Php84/Rector/Foreach_/ForeachToArrayAnyRector/Fixture/boolean_assignment_basic_usage.php.inc
Show resolved
Hide resolved
|
Okay, let's give it a try, thank you @Orest-Divintari |
|
This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work. |
There is already a rule to convert foreach that contains a break statement with array_any. This pr is to add support to the existing rule to convert foreach with early return to array_any