Completed
Push — master ( 8ceb96...b9cd6e )
by Iman
12:39 queued 09:32
created

HeyMan   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 7
eloc 12
dl 0
loc 36
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A turnOn() 0 3 1
A turnOff() 0 3 1
A forget() 0 3 1
A mapping() 0 7 1
A __call() 0 5 3
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
        foreach ($this->mapping() as $className => $methods) {
27 102
            if (str_contains($method, $methods)) {
28 102
                return app($className)->$method(...$args);
29
            }
30
        }
31
    }
32
33
    /**
34
     * @return array
35
     */
36 102
    private function mapping(): array
37
    {
38
        return [
39 102
            RouteSituations::class     => ['Send', 'Url', 'Route', 'Action'],
40
            ViewSituations::class      => ['View'],
41
            EloquentSituations::class  => ['Fetch', 'Create', 'Update', 'Save', 'Delete'],
42
            EventSituations::class     => ['Event'],
43
        ];
44
    }
45
}
46