Skip to content

Commit 4bc73cf

Browse files
authored
[Php84] Skip variable extraction with return early on ForeachToArrayAllRector (#7591)
1 parent dc3a19c commit 4bc73cf

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php84\Rector\Foreach_\ForeachToArrayAllRector\Fixture;
4+
5+
class SkipOnVariableExtract
6+
{
7+
private function allDependencyHasType(array $dependencies, string $type): bool {
8+
foreach ($dependencies as ['type' => $currentType]) {
9+
if ($currentType !== $type) {
10+
return false;
11+
}
12+
}
13+
14+
return true;
15+
}
16+
}

rules/Php84/Rector/Foreach_/ForeachToArrayAllRector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ private function isValidEarlyReturnForeachStructure(Foreach_ $foreach): bool
276276
return false;
277277
}
278278

279+
if (! $foreach->valueVar instanceof Variable) {
280+
return false;
281+
}
282+
279283
$type = $this->nodeTypeResolver->getNativeType($foreach->expr);
280284

281285
return $type->isArray()

0 commit comments

Comments
 (0)