Test Failed
Pull Request — master (#19)
by Flo
03:12
created

Observer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Faulancer\Event;
4
5
use Faulancer\Service\Config;
6
use Faulancer\ServiceLocator\ServiceLocator;
7
8
/**
9
 * Class Observer
10
 * @package Faulancer\Event
11
 * @author  Florian Knapp <[email protected]>
12
 */
13
class Observer
14
{
15
16
    /** @var self */
17
    protected static $instance;
18
19
    /** @var AbstractListener[] */
20
    protected static $listener = [];
21
22
    /**
23
     * Observer constructor (private).
24
     */
25
    private function __construct() {}
26
27
    /**
28
     * @return self
29
     */
30
    public static function instance()
31
    {
32
        if (!self::$instance) {
33
34
            /** @var Config $config */
35
            $config = ServiceLocator::instance()->get(Config::class);
36
            self::$listener = $config->get('eventListener');
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('eventListener') of type * is incompatible with the declared type array<integer,object<Fau...vent\AbstractListener>> of property $listener.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
            self::$instance = new self();
38
39
        }
40
41
        return self::$instance;
42
    }
43
44
    /**
45
     * @param AbstractEventType $eventType
46
     */
47
    public function trigger(AbstractEventType $eventType)
48
    {
49
        foreach (self::$listener as $typeName => $listenerList) {
50
51
            /** @var AbstractListener[] $listenerList */
52
            foreach ($listenerList as $listener) {
53
54
                if ($typeName === $eventType::EVENT_TYPE) {
55
56
                    /** @var AbstractListener $listener */
57
                    $listener = new $listener($eventType);
58
                    $listener->create()->getCallback()->execute($eventType);
0 ignored issues
show
Bug introduced by
The method getCallback cannot be called on $listener->create() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
59
60
                }
61
62
            }
63
64
65
66
        }
67
68
    }
69
70
}