Completed
Push — master ( 5b8b4e...9f490d )
by Iman
07:14
created

RouteSituations   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 122
rs 10
c 0
b 0
f 0
wmc 11

11 Methods

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