Total Complexity | 7 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | trait SplSubjectWithObserversTrait |
||
15 | { |
||
16 | /** @var ObserversSet */ |
||
17 | private $observers; |
||
18 | |||
19 | 25 | private function constructSplSubjectWithObservers(): void |
|
20 | { |
||
21 | 25 | $this->observers = new ObserversSet(); |
|
22 | } |
||
23 | |||
24 | 4 | public function attach(SplObserver $observer): void |
|
27 | } |
||
28 | |||
29 | 1 | public function detach(SplObserver $observer): void |
|
32 | } |
||
33 | |||
34 | 24 | public function notify(): void |
|
35 | { |
||
36 | 24 | if (! $this instanceof SplSubject) { |
|
37 | /** @psalm-var object $this Psalm identify $this as empty-mixed */ |
||
38 | 1 | throw new LogicException(sprintf('Object %s is not an instance of SplSubject', get_class($this))); |
|
39 | } |
||
40 | 23 | foreach ($this->getObservers() as $observer) { |
|
41 | 3 | $observer->update($this); |
|
42 | } |
||
43 | } |
||
44 | |||
45 | 24 | private function getObservers(): ObserversSet |
|
48 | } |
||
49 | } |
||
50 |