Completed
Push — master ( c9a923...7591c0 )
by Karsten
03:22
created

GroupByOperation   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 13 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\AbstractUnaryFunctionOperation;
12
13
/**
14
 * GroupOperation
15
 *
16
 * @author Karsten J. Gerber <[email protected]>
17
 */
18
class GroupByOperation extends AbstractUnaryFunctionOperation implements FullSetOperation
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23 6
    public function apply(\Iterator $set)
24
    {
25 6
        $ret  = [];
26 6
        $func = $this->function;
27
28 6
        foreach ($set as $item) {
29 6
            $group = $func($item);
30
31 6
            $ret[$group][] = $item;
32 6
        }
33
34 6
        return new \ArrayIterator($ret);
35
    }
36
}
37