Completed
Pull Request — master (#39)
by Iman
09:05 queued 06:11
created

Consider   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 72
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

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