Passed
Push — master ( 12242c...e9b436 )
by Iman
08:01
created

RouteSituations::getNormalizedArgs()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 15
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace Imanghafoori\HeyMan\WatchingStrategies\Routes;
4
5
use Imanghafoori\HeyMan\Situations\BaseSituation;
6
7
final class RouteSituations extends BaseSituation
8
{
9
    public function hasMethod($method)
10
    {
11
        return in_array($method, [
12
            'whenYouVisitUrl',
13
            'whenYouSendPost',
14
            'whenYouSendPatch',
15
            'whenYouSendPut',
16
            'whenYouSendDelete',
17
            'whenYouCallAction',
18
            'whenYouHitRouteName',
19
        ]);
20
    }
21
22
    public function __call($method, $args)
23
    {
24
        $args = $this->getNormalizedArgs($method, $args);
25
        $this->setManager(RouterEventManager::class, $args);
26
    }
27
28
    /**
29
     * @param $method
30
     * @param $args
31
     *
32
     * @return array
33
     */
34
    private function getNormalizedArgs($method, $args): array
35
    {
36
        $normalizer = resolve(RouteNormalizer::class);
37
        $method = str_replace('whenYou', '', $method);
38
        if ($method == 'CallAction') {
39
            return $normalizer->normalizeAction($args);
40
        }
41
        if ($method == 'HitRouteName') {
42
            return $args;
43
        }
44
45
        $method = str_replace('VisitUrl', 'SendGet', $method);
46
        $method = str_replace('Send', '', $method);
47
48
        return $normalizer->normalizeUrl($args, strtoupper($method));
49
    }
50
}
51