Completed
Push — master ( e259d1...e66ca6 )
by Iman
06:13
created

EventManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 35
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 5 1
A startGuarding() 0 6 1
A start() 0 4 2
1
<?php
2
3
namespace Imanghafoori\HeyMan\WatchingStrategies;
4
5
use Illuminate\Support\Facades\Event;
6
use Imanghafoori\HeyMan\HeyManSwitcher;
7
8
class EventManager
9
{
10
    private $events;
11
12
    private $data = [];
13
14
    /**
15
     * BasicEventManager constructor.
16
     *
17
     * @param $events
18
     *
19 8
     * @return EventManager
20
     */
21 8
    public function init(array $events): self
22
    {
23 8
        $this->events = $events;
24
25
        return $this;
26
    }
27
28
    /**
29 8
     * @param $listener
30
     */
31 8
    public function startGuarding(callable $listener)
32 8
    {
33
        $r = $this->events;
34
        $t = app(HeyManSwitcher::class)->wrapForIgnorance($listener, 'event');
35
36
        $this->data[] = [$r, $t];
37
    }
38
39
    public function start()
40
    {
41
        foreach ($this->data as $data) {
42
            Event::listen(...$data);
0 ignored issues
show
Bug introduced by
The call to Illuminate\Support\Facades\Event::listen() has too few arguments starting with listener. ( Ignorable by Annotation )

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

42
            Event::/** @scrutinizer ignore-call */ 
43
                   listen(...$data);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
43
        }
44
    }
45
}
46