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

ViewEventManager::start()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 0
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 12
rs 10
c 0
b 0
f 0
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