Completed
Push — master ( 33a5ea...6cf420 )
by Mehmet
01:22
created

AbstractValueObjectObserverManager::notify()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 13
rs 10
cc 3
nc 4
nop 1
1
<?php
2
3
namespace ValueObjects\Common\Observers;
4
5
use SplObjectStorage;
6
7
abstract class AbstractValueObjectObserverManager
8
{
9
    protected SplObjectStorage $observers;
10
    protected array $notifying = [];
11
12
    public function detachAll(): void
13
    {
14
        foreach ($this->observers as $observer) {
15
            $this->observers->detach($observer);
16
        }
17
    }
18
19
    public function getObservers(): SplObjectStorage
20
    {
21
        return $this->observers;
22
    }
23
24
    public function notify(string $event): void
25
    {
26
        if (isset($this->notifying[$event])) {
27
            return;
28
        }
29
30
        $this->notifying[$event] = null;
31
        try {
32
            foreach ($this->observers as $observer) {
33
                $this->fire($observer, $event);
0 ignored issues
show
Bug introduced by
The method fire() does not exist on ValueObjects\Common\Obse...ueObjectObserverManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
                $this->/** @scrutinizer ignore-call */ 
34
                       fire($observer, $event);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
            }
35
        } finally {
36
            unset($this->notifying[$event]);
37
        }
38
    }
39
}
40