Completed
Push — master ( 29d79e...8aac64 )
by Iman
09:16
created

RouteSituations::watchRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan\Situations;
4
5
use Imanghafoori\HeyMan\Normilizers\RouteNormalizer;
6
use Imanghafoori\HeyMan\WatchingStrategies\RouterEventManager;
7
8
class RouteSituations extends BaseSituation
9
{
10
    public function hasMethod($method)
11
    {
12
        return in_array($method, [
13
            'whenYouVisitUrl',
14
            'whenYouSendPost',
15
            'whenYouSendPatch',
16
            'whenYouSendPut',
17
            'whenYouSendDelete',
18 35
            'whenYouCallAction',
19
            'whenYouHitRouteName'
20 35
        ]);
21
    }
22
23
    public function __call($method, $args)
24
    {
25
        $method = str_replace('whenYou', '', $method);
26
        $args = $this->getNormalizedArgs($method, $args);
27
        $this->chain->eventManager = app(RouterEventManager::class)->init($args);
0 ignored issues
show
Documentation Bug introduced by
It seems like app(Imanghafoori\HeyMan\...er::class)->init($args) of type Imanghafoori\HeyMan\Watc...gies\RouterEventManager is incompatible with the declared type Imanghafoori\HeyMan\ListenerApplier of property $eventManager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
28 1
    }
29
30 1
    /**
31
     * @param $method
32
     * @param $args
33
     * @return array
34
     */
35
    private function getNormalizedArgs($method, $args): array
36
    {
37
        $normalizer = app(RouteNormalizer::class);
38 1
        if ($method == 'CallAction') {
39
            return $normalizer->normalizeAction($args);
40 1
        }
41
        if ($method == 'HitRouteName') {
42
            return $args;
43
        }
44
45
        $method = str_replace('VisitUrl', 'SendGet', $method);
46
        $method = str_replace('Send', '', $method);
47
        return $normalizer->normalizeUrl($args, strtoupper($method));
48 2
49
    }
50
}
51