Completed
Push — master ( c694b5...a5ec91 )
by Iman
05:01
created

Consider::turn()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 2
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
class Consider
6
{
7
    private $mode;
8
9 12
    public function __construct($mode)
10
    {
11 12
        $this->mode = $mode;
12 12
    }
13
14 2
    public function eloquentChecks(callable $closure = null)
15
    {
16 2
        $this->turn('heyman_ignore_eloquent', $closure);
17 2
    }
18
19 1
    public function viewChecks(callable $closure = null)
20
    {
21 1
        $this->turn('heyman_ignore_view', $closure);
22 1
    }
23
24 9
    public function routeChecks(callable $closure = null)
25
    {
26 9
        $this->turn('heyman_ignore_route', $closure);
27 9
    }
28
29
    public function eventChecks(callable $closure = null)
30
    {
31
        $this->turn('heyman_ignore_event', $closure);
32
    }
33
34
    public function allChecks()
35
    {
36
        $this->eventChecks();
37
        $this->eloquentChecks();
38
        $this->routeChecks();
39
        $this->viewChecks();
40
    }
41
42
    /**
43
     * @param $key
44
     * @param callable|null $closure
45
     */
46 12
    private function turn($key, callable $closure = null)
47
    {
48 12
        $current = config($key);
49 12
        config()->set($key, [
50
            'turnOff' => true,
51
            'turnOn'  => false,
52 12
        ][$this->mode]);
53
54 12
        if (is_null($closure)) {
55 11
            return ;
56
        }
57 1
        $closure();
58 1
        config()->set($key, $current);
59 1
    }
60
}
61