Completed
Pull Request — master (#39)
by Iman
09:05 queued 06:11
created

RouteSituations::whenYouReachRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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