Completed
Pull Request — master (#109)
by ARCANEDEV
04:47
created

Router::transRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 1
b 0
f 0
1
<?php namespace Arcanedev\Localization\Routing;
2
3
use Closure;
4
5
/**
6
 * Class     Router
7
 *
8
 * @package  Arcanedev\Localization\Routing
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @mixin \Illuminate\Routing\Router
12
 */
13
class Router
14
{
15
    /* -----------------------------------------------------------------
16
     |  Getters & Setters
17
     | -----------------------------------------------------------------
18
     */
19
20
    /**
21
     * Get active middlewares.
22
     *
23
     * @return Closure|array
24
     */
25
    protected function getActiveMiddlewares()
26
    {
27 252
        return function() {
28 252
            return array_keys(array_filter(
29 252
                config('localization.route.middleware', [])
30
            ));
31 252
        };
32
    }
33
34
    /* -----------------------------------------------------------------
35
     |  Route Methods
36
     | -----------------------------------------------------------------
37
     */
38
39
    /**
40
     * Create a route group with shared attributes.
41
     *
42
     * @return Closure
43
     */
44
    public function localizedGroup()
45
    {
46 252
        return function(Closure $callback, array $attributes = []) {
47 252
            $attributes = array_merge($attributes, [
48 252
                'prefix' => localization()->setLocale(),
49 252
                'middleware' => $this->getActiveMiddlewares(),
50
            ]);
51
52 252
            $this->group(array_filter($attributes), $callback);
0 ignored issues
show
Bug introduced by
The method group() does not seem to exist on object<Arcanedev\Localization\Routing\Router>.

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...
53 252
        };
54
    }
55
56
    /**
57
     * Register a new translated GET route with the router.
58
     *
59
     * @return Closure|\Illuminate\Routing\Route
60
     */
61
    public function transGet()
62
    {
63 252
        return function($trans, $action) {
64 252
            return $this->get(
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<Arcanedev\Localization\Routing\Router>.

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...
65 252
                localization()->transRoute($trans), $action
66
            );
67 252
        };
68
    }
69
70
    /**
71
     * Register a new translated POST route with the router.
72
     *
73
     * @return Closure|\Illuminate\Routing\Route
74
     */
75
    public function transPost()
76
    {
77 252
        return function($trans, $action) {
78 252
            return $this->post(
0 ignored issues
show
Bug introduced by
The method post() does not seem to exist on object<Arcanedev\Localization\Routing\Router>.

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...
79 252
                localization()->transRoute($trans), $action
80
            );
81 252
        };
82
    }
83
84
    /**
85
     * Register a new translated PUT route with the router.
86
     *
87
     * @return Closure|\Illuminate\Routing\Route
88
     */
89
    public function transPut()
90
    {
91 252
        return function($trans, $action) {
92 252
            return $this->put(
0 ignored issues
show
Bug introduced by
The method put() does not seem to exist on object<Arcanedev\Localization\Routing\Router>.

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...
93 252
                localization()->transRoute($trans), $action
94
            );
95 252
        };
96
    }
97
98
    /**
99
     * Register a new translated PATCH route with the router.
100
     *
101
     * @return Closure|\Illuminate\Routing\Route
102
     */
103
    public function transPatch()
104
    {
105 252
        return function($trans, $action) {
106 252
            return $this->patch(
0 ignored issues
show
Bug introduced by
The method patch() does not seem to exist on object<Arcanedev\Localization\Routing\Router>.

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...
107 252
                localization()->transRoute($trans), $action
108
            );
109 252
        };
110
    }
111
112
    /**
113
     * Register a new translated DELETE route with the router.
114
     *
115
     * @return Closure|\Illuminate\Routing\Route
116
     */
117
    public function transDelete()
118
    {
119 252
        return function($trans, $action) {
120 252
            return $this->delete(
0 ignored issues
show
Bug introduced by
The method delete() does not exist on Arcanedev\Localization\Routing\Router. Did you maybe mean transDelete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
121 252
                localization()->transRoute($trans), $action
122
            );
123 252
        };
124
    }
125
126
    /**
127
     * Register a new translated OPTIONS route with the router.
128
     *
129
     * @return Closure|\Illuminate\Routing\Route
130
     * @internal param string $trans
131
     * @internal param array|Closure|string $action
132
     *
133
     */
134
    public function transOptions()
135
    {
136 252
        return function($trans, $action) {
137 252
            return $this->options(
0 ignored issues
show
Bug introduced by
The method options() does not exist on Arcanedev\Localization\Routing\Router. Did you maybe mean transOptions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
138 252
                localization()->transRoute($trans), $action
139
            );
140 252
        };
141
    }
142
143
    /**
144
     * Register a new translated any route with the router.
145
     *
146
     * @return Closure|\Illuminate\Routing\Route
147
     * @internal param string $trans
148
     * @internal param array|Closure|string $action
149
     *
150
     */
151
    public function transAny()
152
    {
153 252
        return function($trans, $action) {
154 252
            return $this->any(
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<Arcanedev\Localization\Routing\Router>.

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...
155 252
                localization()->transRoute($trans), $action
156
            );
157 252
        };
158
    }
159
}
160