FlattenOperation   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 9
dl 0
loc 31
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A flatten() 0 13 4
A apply() 0 7 1
1
<?php
2
/**
3
 * File was created 06.05.2015 22:14
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
12
/**
13
 * FlattenOperation
14
 *
15
 * @author Karsten J. Gerber <[email protected]>
16
 */
17
class FlattenOperation implements FullSetOperation
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 4
    public function apply(\Iterator $set)
23
    {
24 4
        $result = new \ArrayIterator();
25
26 4
        $this->flatten($result, $set);
27
28 4
        return $result;
29
    }
30
31
    /**
32
     * @param \ArrayIterator $result
33
     * @param mixed|mixed[]  $input
34
     */
35 4
    private function flatten(\ArrayIterator $result, $input)
36
    {
37 4
        if (is_array($input) || $input instanceof \Traversable) {
38
39
            /** @noinspection ForeachSourceInspection */
40 4
            foreach ($input as $item) {
41 3
                $this->flatten($result, $item);
42
            }
43
44 4
            return;
45
        }
46
47 3
        $result->append($input);
48 3
    }
49
}
50