Passed
Push — master ( 68dd01...f1d925 )
by Iman
13:01 queued 09:57
created

Consider::allChecks()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
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);
0 ignored issues
show
Bug introduced by
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 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.

Loading history...
Bug introduced by
$args is expanded, but the parameter $closure of Imanghafoori\HeyMan\Switching\Consider::turn() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        return $this->turn(self::methods[$method], /** @scrutinizer ignore-type */ ...$args);
Loading history...
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