Completed
Pull Request — master (#47)
by Iman
13:15 queued 09:06
created

RouteSituations::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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 103
    public function hasMethod($method)
11
    {
12 103
        return in_array($method, [
13 103
            'whenYouVisitUrl',
14
            'whenYouSendPost',
15
            'whenYouSendPatch',
16
            'whenYouSendPut',
17
            'whenYouSendDelete',
18
            'whenYouCallAction',
19
            'whenYouHitRouteName',
20
        ]);
21
    }
22
23 58
    public function __call($method, $args)
24
    {
25 58
        $method = str_replace('whenYou', '', $method);
26 58
        $args = $this->getNormalizedArgs($method, $args);
27 58
        $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 58
    }
29
30
    /**
31
     * @param $method
32
     * @param $args
33
     *
34
     * @return array
35
     */
36 58
    private function getNormalizedArgs($method, $args): array
37
    {
38 58
        $normalizer = app(RouteNormalizer::class);
39 58
        if ($method == 'CallAction') {
40 10
            return $normalizer->normalizeAction($args);
41
        }
42 51
        if ($method == 'HitRouteName') {
43 11
            return $args;
44
        }
45
46 40
        $method = str_replace('VisitUrl', 'SendGet', $method);
47 40
        $method = str_replace('Send', '', $method);
48
49 40
        return $normalizer->normalizeUrl($args, strtoupper($method));
50
    }
51
}
52