Passed
Push — master ( 4f5a04...f7b3b1 )
by Chris
07:47
created

ForeachLoop::iterate()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 9.2876

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 12
ccs 4
cts 9
cp 0.4444
rs 9.6111
cc 5
nc 5
nop 2
crap 9.2876
1
<?php
2
3
namespace WebTheory\Collection\Iteration;
4
5
use WebTheory\Collection\Contracts\LoopInterface;
6
use WebTheory\Collection\Enum\LoopAction;
7
8
class ForeachLoop implements LoopInterface
9
{
10 3
    public function iterate(iterable $items, callable $callback): void
11
    {
12 3
        foreach ($items as $key => $item) {
13 3
            $action = $callback($item, $key, $items);
14
15 3
            if ($action instanceof LoopAction) {
16
                switch ($action->getValue()) {
17
                    case LoopAction::Break:
18
                        break 2;
19
20
                    case LoopAction::Continue:
21
                        continue 2;
22
                }
23
            }
24
        }
25
    }
26
}
27