imanghafoori1 /
laravel-heyman
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Imanghafoori\HeyMan\Switching; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Class Consider. |
||
| 7 | * |
||
| 8 | * @method null eventChecks(null|callable $closure = null) |
||
| 9 | * @method null viewChecks(null|callable $closure = null) |
||
| 10 | * @method null routeChecks(null|callable $closure = null) |
||
| 11 | * @method null eloquentChecks(null|callable $closure = null) |
||
| 12 | * @method null validationChecks(null|callable $closure = null) |
||
| 13 | */ |
||
| 14 | class Consider |
||
| 15 | { |
||
| 16 | public static $methods = [ |
||
| 17 | 'validationChecks' => 'validation', |
||
| 18 | ]; |
||
| 19 | |||
| 20 | private $mode; |
||
| 21 | |||
| 22 | 121 | public static function add($key, $listener) |
|
| 23 | { |
||
| 24 | 121 | self::$methods[$key] = $listener; |
|
| 25 | 121 | } |
|
| 26 | |||
| 27 | 17 | public function __construct($mode) |
|
| 28 | { |
||
| 29 | 17 | $this->mode = $mode; |
|
| 30 | 17 | } |
|
| 31 | |||
| 32 | 17 | public function __call($method, $args) |
|
| 33 | { |
||
| 34 | 17 | return $this->turn(self::$methods[$method], ...$args); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
Are you sure the usage of
$this->turn(self::methods[$method], $args) targeting Imanghafoori\HeyMan\Switching\Consider::turn() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 35 | } |
||
| 36 | |||
| 37 | 3 | public function allChecks() |
|
| 38 | { |
||
| 39 | 3 | foreach (self::$methods as $method => $type) { |
|
| 40 | 3 | $this->$method(); |
|
| 41 | } |
||
| 42 | 3 | } |
|
| 43 | |||
| 44 | /** |
||
| 45 | * @param $key |
||
| 46 | * @param callable|null $closure |
||
| 47 | */ |
||
| 48 | 17 | private function turn($key, callable $closure = null) |
|
| 49 | { |
||
| 50 | 17 | $key = 'heyman_ignore_'.$key; |
|
| 51 | |||
| 52 | 17 | $current = config($key); |
|
| 53 | 17 | $this->changeMode($key); |
|
| 54 | |||
| 55 | 17 | if (is_null($closure)) { |
|
| 56 | 16 | return; |
|
| 57 | } |
||
| 58 | 1 | $result = $closure(); |
|
| 59 | 1 | config()->set($key, $current); |
|
| 60 | |||
| 61 | 1 | return $result; |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param $key |
||
| 66 | */ |
||
| 67 | 17 | private function changeMode($key) |
|
| 68 | { |
||
| 69 | 17 | config()->set($key, [ |
|
| 70 | 'turnOff' => true, |
||
| 71 | 'turnOn' => false, |
||
| 72 | 17 | ][$this->mode]); |
|
| 73 | 17 | } |
|
| 74 | } |
||
| 75 |