Completed
Pull Request — master (#31)
by Iman
10:47 queued 08:04
created

EventManager::forgetAbout()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

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

41
            Event::/** @scrutinizer ignore-call */ 
42
                   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...
42
        }
43 101
    }
44
45 2
    public function forgetAbout($events)
46
    {
47 2
        foreach ($events as $event) {
48 2
            foreach ($this->data as $i => $data) {
49 2
                if (($key = array_search($event, $data[0])) !== false) {
50 2
                    unset($this->data[$i][0][$key]);
51
                }
52
            }
53
        }
54 2
    }
55
}
56