Completed
Push — master ( c7a28f...3c1051 )
by Iman
10:58 queued 08:05
created

HeyMan::__call()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Imanghafoori\HeyMan\Hooks\EloquentHooks;
6
use Imanghafoori\HeyMan\Hooks\EventHooks;
7
use Imanghafoori\HeyMan\Normilizers\InputNormalizer;
8
use Imanghafoori\HeyMan\Situations\RouteSituations;
9
use Imanghafoori\HeyMan\Situations\ViewSituations;
10
11
class HeyMan
12
{
13
    use EloquentHooks, EventHooks, InputNormalizer;
14
15
    private $chain;
16
17
    /**
18
     * HeyMan constructor.
19
     *
20
     * @param Chain $chain
21
     */
22 102
    public function __construct(Chain $chain)
23
    {
24 102
        $this->chain = $chain;
25 102
    }
26
27 15
    public function turnOff(): Consider
28
    {
29 15
        return new Consider('turnOff');
30
    }
31
32 1
    public function turnOn(): Consider
33
    {
34 1
        return new Consider('turnOn');
35
    }
36
37 13
    public function forget(): Forget
38
    {
39 13
        return new Forget();
40
    }
41
42 77
    public function __call($method, $args)
43
    {
44 77
        foreach ($this->mapping() as $className => $methods) {
45 77
            if (str_contains($method, $methods)) {
46 77
                return app($className)->$method(...$args);
47
            }
48
        }
49
    }
50
51
    /**
52
     * @return array
53
     */
54 77
    private function mapping(): array
55
    {
56
        return [
57 77
            RouteSituations::class => ['Send', 'Url', 'Route', 'Action'],
58
            ViewSituations::class  => ['View'],
59
        ];
60
    }
61
}
62