ObserversSet   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 49
rs 10
c 2
b 0
f 0
ccs 18
cts 18
cp 1
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A count() 0 3 1
A attach() 0 3 1
A detach() 0 3 1
A rewind() 0 3 1
A valid() 0 3 1
A key() 0 3 1
A current() 0 3 1
A next() 0 4 1
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