Completed
Push — master ( c6b6d5...70eeeb )
by Iman
06:33
created

Consider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 62
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A viewChecks() 0 3 1
A routeChecks() 0 3 1
A eloquentChecks() 0 3 1
A eventChecks() 0 3 1
A allChecks() 0 7 1
A validationChecks() 0 3 1
A turn() 0 15 2
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
class Consider
6
{
7
    private $mode;
8
9 13
    public function __construct($mode)
10
    {
11 13
        $this->mode = $mode;
12 13
    }
13
14 4
    public function eloquentChecks(callable $closure = null)
15
    {
16 4
        return $this->turn('heyman_ignore_eloquent', $closure);
17
    }
18
19 3
    public function viewChecks(callable $closure = null)
20
    {
21 3
        return $this->turn('heyman_ignore_view', $closure);
22
    }
23
24 9
    public function routeChecks(callable $closure = null)
25
    {
26 9
        return $this->turn('heyman_ignore_route', $closure);
27
    }
28
29 3
    public function eventChecks(callable $closure = null)
30
    {
31 3
        return $this->turn('heyman_ignore_event', $closure);
32
    }
33
34 2
    public function validationChecks(callable $closure = null)
35
    {
36 2
        return $this->turn('heyman_ignore_validation', $closure);
37 2
    }
38 2
39 2
    public function allChecks()
40 2
    {
41
        $this->validationChecks();
42
        $this->eventChecks();
43
        $this->eloquentChecks();
44
        $this->routeChecks();
45
        $this->viewChecks();
46 13
    }
47
48 13
    /**
49 13
     * @param $key
50
     * @param callable|null $closure
51
     */
52 13
    private function turn($key, callable $closure = null)
53
    {
54 13
        $current = config($key);
55 12
        config()->set($key, [
56
            'turnOff' => true,
57 1
            'turnOn'  => false,
58 1
        ][$this->mode]);
59
60 1
        if (is_null($closure)) {
61
            return;
62
        }
63
        $result = $closure();
64
        config()->set($key, $current);
65
66
        return $result;
67
    }
68
}
69