ObserversSet::rewind()   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 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 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EngineWorks\ProgressStatus;
6
7
use Countable;
8
use Iterator;
9
use SplObjectStorage;
10
use SplObserver;
11
12
/**
13
 * @implements Iterator<int, SplObserver>
14
 */
15
class ObserversSet implements Countable, Iterator
16
{
17
    /** @var SplObjectStorage<SplObserver, null> */
18
    private $observers;
19
20 28
    public function __construct()
21
    {
22 28
        $this->observers = new SplObjectStorage();
23
    }
24
25 6
    public function attach(SplObserver $observer): void
26
    {
27 6
        $this->observers->attach($observer);
28
    }
29
30 2
    public function detach(SplObserver $observer): void
31
    {
32 2
        $this->observers->detach($observer);
33
    }
34
35 3
    public function count(): int
36
    {
37 3
        return $this->observers->count();
38
    }
39
40 5
    public function current(): SplObserver
41
    {
42 5
        return $this->observers->current();
43
    }
44
45 5
    public function next(): void
46
    {
47
        /** @infection-ignore-all if omitted create an infinite loop */
48 5
        $this->observers->next();
49
    }
50
51 2
    public function key(): int
52
    {
53 2
        return $this->observers->key();
54
    }
55
56 25
    public function valid(): bool
57
    {
58 25
        return $this->observers->valid();
59
    }
60
61 25
    public function rewind(): void
62
    {
63 25
        $this->observers->rewind();
64
    }
65
}
66