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

ViewEventManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 33
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 5 1
A wrapForIgnorance() 0 5 2
A startGuarding() 0 4 2
1
<?php
2
3
namespace Imanghafoori\HeyMan\WatchingStrategies;
4
5
class ViewEventManager
6
{
7
    private $views = [];
8
9
    /**
10
     * ViewEventManager constructor.
11
     *
12
     * @param $views
13
     *
14
     * @return ViewEventManager
15
     */
16 14
    public function init(array $views): ViewEventManager
17
    {
18 14
        $this->views = $views;
19
20 14
        return $this;
21
    }
22
23
    /**
24
     * @param $listener
25
     */
26 14
    public function startGuarding(callable $listener)
27
    {
28
        foreach ($this->views as $view) {
29 14
            view()->creator($view, $this->wrapForIgnorance($listener));
30 12
        }
31
    }
32 14
33
    private function wrapForIgnorance(callable $callback): callable
34 14
    {
35 14
        return function (...$args) use ($callback) {
36
            if (! config('heyman_ignore_view', false)) {
37 14
                $callback(...$args);
38
            }
39
        };
40
    }
41
}
42