Total Complexity | 10 |
Total Lines | 72 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
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() |
|
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) |
|
82 | 15 | } |
|
83 | } |
||
84 |