Completed
Push — master ( 7bdb8b...9d6e0c )
by Iman
05:12
created

Consider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 56
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 8

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