UniqueOperation   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 27
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A apply() 0 11 3
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
 * UniqueOperation
14
 *
15
 * @author Karsten J. Gerber <[email protected]>
16
 */
17
class UniqueOperation implements FullSetOperation
18
{
19
    /** @var bool */
20
    protected $strict;
21
22
    /**
23
     * @param bool $strict
24
     */
25 9
    public function __construct($strict)
26
    {
27 9
        $this->strict = (bool) $strict;
28 9
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 9
    public function apply(\Iterator $set)
34
    {
35 9
        $result = [];
36
37 9
        foreach ($set as $item) {
38 8
            if (! in_array($item, $result, $this->strict)) {
39 8
                $result[] = $item;
40
            }
41
        }
42
43 9
        return new \ArrayIterator($result);
44
    }
45
}
46