GroupByOperation   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 17
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 12 2
1
<?php
2
/**
3
 * File was created 09.06.2015 06:50
4
 *
5
 * @author Karsten J. Gerber <[email protected]>
6
 */
7
8
namespace PeekAndPoke\Component\Psi\Operation\FullSet;
9
10
use PeekAndPoke\Component\Psi\FullSetOperation;
11
use PeekAndPoke\Component\Psi\Operation\AbstractBinaryFunctionOperation;
12
13
/**
14
 * @author Karsten J. Gerber <[email protected]>
15
 */
16
class GroupByOperation extends AbstractBinaryFunctionOperation implements FullSetOperation
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 8
    public function apply(\Iterator $set)
22
    {
23 8
        $ret  = [];
24 8
        $func = $this->function;
25
26 8
        foreach ($set as $key => $item) {
27 8
            $group = $func($item, $key);
28
29 8
            $ret[$group][] = $item;
30
        }
31
32 8
        return new \ArrayIterator($ret);
33
    }
34
}
35