Passed
Push — master ( b9cd6e...b2eaf8 )
by Iman
05:46
created

HeyMan::writeDebugInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Imanghafoori\HeyMan\Situations\{EloquentSituations, EventSituations, RouteSituations, ViewSituations};
6
7
class HeyMan
8
{
9 15
    public function turnOff(): Consider
10
    {
11 15
        return new Consider('turnOff');
12
    }
13
14 1
    public function turnOn(): Consider
15
    {
16 1
        return new Consider('turnOn');
17
    }
18
19 13
    public function forget(): Forget
20
    {
21 13
        return new Forget();
22
    }
23
24 102
    public function __call($method, $args)
25
    {
26 102
        $this->writeDebugInfo(debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2));
27 102
28 102
        foreach ($this->situations() as $className) {
29
            if (method_exists($className, $method)) {
30
                return app($className)->$method(...$args);
31
            }
32
        }
33
    }
34
35
    /**
36 102
     * @return array
37
     */
38
    private function situations(): array
39 102
    {
40
        return [
41
            RouteSituations::class,
42
            ViewSituations::class,
43
            EloquentSituations::class,
44
            EventSituations::class,
45
        ];
46
    }
47
48
    /**
49
     * @param $d
50
     */
51
    private function writeDebugInfo($d)
52
    {
53
        app(Chain::class)->debugInfo = array_only($d[1], ['file', 'line', 'args']);
54
    }
55
}
56