-
-
Notifications
You must be signed in to change notification settings - Fork 742
Closed
rectorphp/rector-src
#7193Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | 2.1.4 |
ForeachToArrayAnyRector refactors a foreach which extracts its item value. It looks like it doesn't know what to do then. The code is broken.
Minimal PHP Code Causing Issue
private function hasDependencyType(array $dependencies, string $type): bool {
- /* @noinspection PhpLoopCanBeReplacedWithStdFunctionCallsInspection */
- foreach ($dependencies as ['type' => $currentType]) {
- if ($currentType === $type) {
- return true;
- }
- }
-
- return false;
+ return array_any($dependencies, fn() => $currentType === $type);
}Expected Behaviour
Either leave the code or correctly refactor it.
A correct version would look like:
private function hasDependencyType(array $dependencies, string $type): bool {
return array_any($dependencies, fn(array $dep) => $dep['type'] === $type);
}Reactions are currently unavailable