Completed
Push — master ( e1d039...94c97f )
by Iman
09:21
created

ViewEventManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 37
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

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