Completed
Push — master ( a52e49...d03ec2 )
by Iman
09:53
created

HeyMan::startChain()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3

Importance

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