Completed
Pull Request — master (#40)
by Iman
08:07 queued 05:12
created

HeyMan   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 48
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A turnOn() 0 3 1
A turnOff() 0 3 1
A forget() 0 3 1
A mapping() 0 5 1
A __call() 0 5 3
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