DistinctStream::accept()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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