Completed
Push — master ( 2a7c0c...5b0aeb )
by Iman
06:22
created

RouteHooks::whenYouHitRouteName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan\Hooks;
4
5
use Imanghafoori\HeyMan\Normilizers\ActionNormalizer;
6
use Imanghafoori\HeyMan\WatchingStrategies\RouterEventManager;
7
use Imanghafoori\HeyMan\YouShouldHave;
8
9
trait RouteHooks
10
{
11
    use ActionNormalizer;
12
13
    /**
14
     * @param mixed ...$url
15
     *
16
     * @return YouShouldHave
17
     */
18 35
    public function whenYouVisitUrl(...$url): YouShouldHave
19
    {
20 35
        return $this->authorizeURL($url, 'GET');
21
    }
22
23
    /**
24
     * @param mixed ...$url
25
     *
26
     * @return YouShouldHave
27
     */
28 1
    public function whenYouSendPost(...$url): YouShouldHave
29
    {
30 1
        return $this->authorizeURL($url, 'POST');
31
    }
32
33
    /**
34
     * @param mixed ...$url
35
     *
36
     * @return YouShouldHave
37
     */
38 1
    public function whenYouSendPatch(...$url): YouShouldHave
39
    {
40 1
        return $this->authorizeURL($url, 'PATCH');
41
    }
42
43
    /**
44
     * @param mixed ...$url
45
     *
46
     * @return YouShouldHave
47
     */
48 2
    public function whenYouSendPut(...$url): YouShouldHave
49
    {
50 2
        return $this->authorizeURL($url, 'PUT');
51
    }
52
53
    /**
54
     * @param mixed ...$url
55
     *
56
     * @return YouShouldHave
57
     */
58 1
    public function whenYouSendDelete(...$url): YouShouldHave
59
    {
60 1
        return $this->authorizeURL($url, 'DELETE');
61
    }
62
63
    /**
64
     * @param mixed ...$routeName
65
     *
66
     * @return YouShouldHave
67
     */
68 11
    public function whenYouHitRouteName(...$routeName): YouShouldHave
69
    {
70 11
        return $this->authorizeRoute($this->normalizeInput($routeName));
0 ignored issues
show
Bug introduced by
The method normalizeInput() does not exist on Imanghafoori\HeyMan\Hooks\RouteHooks. Did you maybe mean normalizeUrl()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
        return $this->authorizeRoute($this->/** @scrutinizer ignore-call */ normalizeInput($routeName));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
    }
72
73
    /**
74
     * @deprecated
75
     * @param mixed ...$routeName
76
     *
77
     * @return YouShouldHave
78 10
     */
79
    public function whenYouReachRoute(...$routeName): YouShouldHave
80 10
    {
81
        return $this->whenYouHitRouteName(...$routeName);
82 10
    }
83
84
    /**
85
     * @param mixed ...$action
86
     *
87
     * @return YouShouldHave
88
     */
89
    public function whenYouCallAction(...$action): YouShouldHave
90 58
    {
91
        $action = $this->normalizeAction($action);
92 58
93
        return $this->authorizeRoute($action);
94 58
    }
95
96
    /**
97
     * @param $value
98
     *
99
     * @return YouShouldHave
100
     */
101
    private function authorizeRoute($value): YouShouldHave
102
    {
103 40
        $this->chain->eventManager = app(RouterEventManager::class)->init($value);
104
105 40
        return app(YouShouldHave::class);
106
    }
107
108
    /**
109
     * @param $url
110
     * @param $verb
111
     *
112
     * @return YouShouldHave
113
     */
114
    private function authorizeURL($url, $verb): YouShouldHave
115
    {
116
        return $this->authorizeRoute($this->normalizeUrl($url, $verb));
117
    }
118
}
119