Completed
Push — master ( e66ca6...e1d039 )
by Iman
10:09 queued 06:02
created

EventManager::startGuarding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
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
     * @return EventManager
20
     */
21 8
    public function init(array $events): self
22
    {
23 8
        $this->events = $events;
24
25 8
        return $this;
26
    }
27
28
    /**
29
     * @param $listener
30
     */
31 8
    public function startGuarding(callable $listener)
32
    {
33 8
        $r = $this->events;
34 8
        $t = app(HeyManSwitcher::class)->wrapForIgnorance($listener, 'event');
35
36 8
        $this->data[] = [$r, $t];
37 8
    }
38
39 91
    public function start()
40
    {
41 91
        foreach ($this->data as $data) {
42 8
            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 91
    }
45
}
46