1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Imanghafoori\HeyMan\Switching; |
4
|
|
|
|
5
|
|
|
use Imanghafoori\HeyMan\WatchingStrategies\{EloquentEventsManager, EventManager, RouterEventManager, ViewEventManager}; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Consider |
9
|
|
|
* |
10
|
|
|
* @method null eventChecks(null|callable $closure = null) |
11
|
|
|
* @method null viewChecks(null|callable $closure = null) |
12
|
|
|
* @method null routeChecks(null|callable $closure = null) |
13
|
|
|
* @method null eloquentChecks(null|callable $closure = null) |
14
|
15 |
|
* @method null validationChecks(null|callable $closure = null) |
15
|
|
|
*/ |
16
|
15 |
|
class Consider |
17
|
15 |
|
{ |
18
|
|
|
private $mode; |
19
|
5 |
|
|
20
|
|
|
public function __construct($mode) |
21
|
5 |
|
{ |
22
|
|
|
$this->mode = $mode; |
23
|
|
|
} |
24
|
4 |
|
|
25
|
|
|
public function __call($method, $args) |
26
|
4 |
|
{ |
27
|
|
|
$m = $this->methods(); |
28
|
|
|
|
29
|
10 |
|
return $this->turn($m[$method], ...$args); |
|
|
|
|
30
|
|
|
} |
31
|
10 |
|
|
32
|
|
|
public function allChecks() |
33
|
|
|
{ |
34
|
4 |
|
foreach($this->methods() as $method => $type){ |
35
|
|
|
$this->$method(); |
36
|
4 |
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
4 |
|
/** |
40
|
|
|
* @param $key |
41
|
4 |
|
* @param callable|null $closure |
42
|
|
|
*/ |
43
|
|
|
private function turn($key, callable $closure = null) |
44
|
3 |
|
{ |
45
|
|
|
$key = 'heyman_ignore_'.$key; |
46
|
3 |
|
|
47
|
3 |
|
$current = config($key); |
48
|
3 |
|
$this->changeMode($key); |
49
|
3 |
|
|
50
|
3 |
|
if (is_null($closure)) { |
51
|
3 |
|
return; |
52
|
|
|
} |
53
|
|
|
$result = $closure(); |
54
|
|
|
config()->set($key, $current); |
55
|
|
|
|
56
|
|
|
return $result; |
57
|
15 |
|
} |
58
|
|
|
|
59
|
15 |
|
/** |
60
|
|
|
* @param $key |
61
|
15 |
|
*/ |
62
|
15 |
|
private function changeMode($key) |
63
|
|
|
{ |
64
|
15 |
|
config()->set($key, [ |
65
|
14 |
|
'turnOff' => true, |
66
|
|
|
'turnOn' => false, |
67
|
1 |
|
][$this->mode]); |
68
|
1 |
|
} |
69
|
|
|
|
70
|
1 |
|
/** |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
private function methods(): array |
74
|
|
|
{ |
75
|
|
|
return [ |
76
|
15 |
|
'eventChecks' => EventManager::class, |
77
|
|
|
'viewChecks' => ViewEventManager::class, |
78
|
15 |
|
'routeChecks' => RouterEventManager::class, |
79
|
|
|
'eloquentChecks' => EloquentEventsManager::class, |
80
|
|
|
'validationChecks' => 'validation', |
81
|
15 |
|
]; |
82
|
15 |
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.