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

EventManager::start()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 6
rs 10
c 0
b 0
f 0
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