Completed
Push — master ( 14f2a3...e42cf7 )
by Iman
10:04
created

RouteHooks::normalizeAction()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

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

69
        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...
70
    }
71
72
    /**
73
     * @param mixed ...$action
74
     *
75 10
     * @return YouShouldHave
76
     */
77 10
    public function whenYouCallAction(...$action): YouShouldHave
78
    {
79 10
        $action = $this->normalizeAction($action);
80
81
        return $this->authorizeRoute($action);
82
    }
83
84
    /**
85
     * @param $value
86
     *
87 58
     * @return YouShouldHave
88
     */
89 58
    private function authorizeRoute($value): YouShouldHave
90
    {
91 58
        $this->chain->eventManager = app(RouterEventManager::class)->init($value);
92
93
        return app(YouShouldHave::class);
94
    }
95
96
    /**
97
     * @param $url
98
     * @param $verb
99
     *
100 40
     * @return YouShouldHave
101
     */
102 40
    private function authorizeURL($url, $verb): YouShouldHave
103
    {
104
        return $this->authorizeRoute($this->normalizeUrl($url, $verb));
105
    }
106
}
107