Skip to content

Commit a9e26ce

Browse files
committed
Add test fixture for skipping assignment before conditional foreach
1 parent 106c760 commit a9e26ce

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector\Fixture;
4+
5+
final class SkipAssignedBeforeInConditionalForeach
6+
{
7+
public function run($data)
8+
{
9+
$list = [];
10+
$groupList = [];
11+
12+
foreach ($data->getItems() as $item) {
13+
if ($item->hasGroup()) {
14+
$groupList[] = ['id' => $item->getGroupId()];
15+
} else {
16+
$list[] = ['id' => $item->getId()];
17+
}
18+
}
19+
20+
foreach ($groupList as $group) {
21+
$list[] = $group;
22+
}
23+
24+
return $list;
25+
}
26+
}

0 commit comments

Comments
 (0)