DistinctStream   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 39
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rewind() 0 5 1
A accept() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
namespace Bdf\Collection\Stream;
4
5
use Bdf\Collection\SetInterface;
6
use FilterIterator;
7
8
/**
9
 * Implementation of StreamInterface::distinct() return value
10
 *
11
 * @internal
12
 */
13
final class DistinctStream extends FilterIterator implements StreamInterface
14
{
15
    use StreamTrait;
16
17
    /**
18
     * @var SetInterface
19
     */
20
    private $set;
21
22
23
    /**
24
     * FilterStream constructor.
25
     *
26
     * @param StreamInterface $stream The stream to filter
27
     * @param SetInterface $set The set used to store elements
28
     */
29 30
    public function __construct(StreamInterface $stream, SetInterface $set)
30
    {
31 30
        parent::__construct($stream);
32
33 30
        $this->set = $set;
34 30
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 30
    public function accept(): bool
40
    {
41 30
        return $this->set->add($this->current());
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 30
    public function rewind(): void
48
    {
49 30
        $this->set->clear();
50
51 30
        parent::rewind();
52 30
    }
53
}
54