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