Completed
Push — master ( 3c1051...50a607 )
by Iman
09:32
created

RouteSituations   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 107
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A whenYouVisitUrl() 0 3 1
A watchRoute() 0 5 1
A whenYouSendPatch() 0 3 1
A watchURL() 0 3 1
A whenYouCallAction() 0 3 1
A whenYouSendPut() 0 3 1
A whenYouReachRoute() 0 3 1
A whenYouSendPost() 0 3 1
A whenYouHitRouteName() 0 3 1
A whenYouSendDelete() 0 3 1
1
<?php
2
3
namespace Imanghafoori\HeyMan\Situations;
4
5
use Imanghafoori\HeyMan\Normilizers\RouteNormalizer;
6
use Imanghafoori\HeyMan\WatchingStrategies\RouterEventManager;
7
use Imanghafoori\HeyMan\YouShouldHave;
8
9
class RouteSituations extends BaseSituation
10
{
11
    use RouteNormalizer;
12
13
    /**
14
     * @param mixed ...$url
15
     *
16
     * @return YouShouldHave
17
     */
18
    public function whenYouVisitUrl(...$url): YouShouldHave
19
    {
20
        return $this->watchURL($url, 'GET');
21
    }
22
23 58
    /**
24
     * @param mixed ...$url
25 58
     *
26 58
     * @return YouShouldHave
27
     */
28
    public function whenYouSendPost(...$url): YouShouldHave
29
    {
30
        return $this->watchURL($url, 'POST');
31
    }
32
33 35
    /**
34
     * @param mixed ...$url
35 35
     *
36
     * @return YouShouldHave
37
     */
38
    public function whenYouSendPatch(...$url): YouShouldHave
39
    {
40
        return $this->watchURL($url, 'PATCH');
41
    }
42
43 1
    /**
44
     * @param mixed ...$url
45 1
     *
46
     * @return YouShouldHave
47
     */
48
    public function whenYouSendPut(...$url): YouShouldHave
49
    {
50
        return $this->watchURL($url, 'PUT');
51
    }
52
53 1
    /**
54
     * @param mixed ...$url
55 1
     *
56
     * @return YouShouldHave
57
     */
58
    public function whenYouSendDelete(...$url): YouShouldHave
59
    {
60
        return $this->watchURL($url, 'DELETE');
61
    }
62
63 2
    /**
64
     * @param mixed ...$routeName
65 2
     *
66
     * @return YouShouldHave
67
     */
68
    public function whenYouHitRouteName(...$routeName): YouShouldHave
69
    {
70
        return $this->watchRoute($this->normalizeInput($routeName));
71
    }
72
73 1
    /**
74
     * @deprecated
75 1
     *
76
     * @param mixed ...$routeName
77
     *
78
     * @return YouShouldHave
79
     */
80
    public function whenYouReachRoute(...$routeName): YouShouldHave
81
    {
82
        return $this->whenYouHitRouteName(...$routeName);
83 11
    }
84
85 11
    /**
86
     * @param mixed ...$action
87
     *
88
     * @return YouShouldHave
89
     */
90
    public function whenYouCallAction(...$action): YouShouldHave
91
    {
92
        return $this->watchRoute($this->normalizeAction($action));
93
    }
94
95
    /**
96
     * @param $value
97
     *
98
     * @return YouShouldHave
99
     */
100
    private function watchRoute($value): YouShouldHave
101
    {
102
        $this->chain->eventManager = app(RouterEventManager::class)->init($value);
0 ignored issues
show
Documentation Bug introduced by
It seems like app(Imanghafoori\HeyMan\...r::class)->init($value) 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...
103
104
        return app(YouShouldHave::class);
105 10
    }
106
107 10
    /**
108
     * @param $url
109
     * @param $verb
110
     *
111
     * @return YouShouldHave
112
     */
113
    private function watchURL($url, $verb): YouShouldHave
114
    {
115 58
        return $this->watchRoute($this->normalizeUrl($url, $verb));
116
    }
117
}
118