Completed
Push — master ( 0df42c...ab08ca )
by Iman
10:11
created

BasicEventManager::wrapForIgnorance()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 1
cts 1
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan\WatchingStrategies;
4
5
use Illuminate\Support\Facades\Event;
6
7
class BasicEventManager
8
{
9
    private $events;
10
11
    /**
12
     * BasicEventManager constructor.
13
     *
14
     * @param $events
15
     *
16
     * @return BasicEventManager
17
     */
18 6
    public function init(array $events): BasicEventManager
19
    {
20 6
        $this->events = $events;
21
22 6
        return $this;
23
    }
24
25
    /**
26
     * @param $listener
27
     */
28 6
    public function startGuarding(callable $listener)
29
    {
30
        Event::listen($this->events, $this->wrapForIgnorance($listener));
31 6
    }
32 5
33
    /**
34 6
     * @param callable $callback
35 6
     * @return \Closure
36 6
     */
37 6
    private function wrapForIgnorance(callable $callback): \Closure
38
    {
39
        return function () use ($callback) {
40
            if (! config('heyman_ignore_event', false)) {
41
                $callback();
42
            }
43
        };
44
    }
45
}
46