Completed
Push — master ( e306f1...c9eaa1 )
by Iman
05:24
created

ViewEventManager::startGuarding()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 1
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
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
     * @return \Imanghafoori\HeyMan\WatchingStrategies\ViewEventManager
14
     */
15 13
    public function init($views)
16
    {
17 13
        $this->views = $views;
18
19 13
        return $this;
20
    }
21
22
    /**
23
     * @param $callback
24
     */
25 13
    public function startGuarding(callable $callback)
26
    {
27
        $callback = function (...$args) use ($callback) {
28 13
            if (! config('heyman_ignore_view', false)) {
29 12
                $callback(...$args);
30
            }
31 13
        };
32
33 13
        foreach ($this->views as $view) {
34 13
            view()->creator($view, $callback);
35
        }
36 13
    }
37
}
38