Completed
Push — master ( 671128...3a40a1 )
by Karsten
02:35
created

UniqueOperation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * File was created 06.05.2015 22:14
4
 *
5
 * @author Karsten J. Gerber <[email protected]>
6
 */
7
namespace PeekAndPoke\Component\Psi\Operation\FullSet;
8
9
use PeekAndPoke\Component\Psi\Interfaces\Operation\FullSetOperationInterface;
10
11
/**
12
 * UniqueOperation
13
 *
14
 * @author Karsten J. Gerber <[email protected]>
15
 */
16
class UniqueOperation implements FullSetOperationInterface
17
{
18
    /** @var bool */
19
    protected $strict;
20
21
    /**
22
     * @param bool $strict
23
     */
24 9
    public function __construct($strict)
25
    {
26 9
        $this->strict = (bool) $strict;
27 9
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 9
    public function apply(\Iterator $set)
33
    {
34 9
        $result = [];
35
36 9
        foreach ($set as $item) {
37 8
            if (! in_array($item, $result, $this->strict)) {
38 8
                $result[] = $item;
39 8
            }
40 9
        }
41
42 9
        return new \ArrayIterator($result);
43
    }
44
}
45