Passed
Branch master (8139c8)
by Henri
07:53 queued 06:32
created
src/Router.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -217,7 +217,7 @@
 block discarded – undo
217 217
             foreach ($route['filters'] as $key => $value) {
218 218
                 $filters[] = $value;
219 219
             }
220
-        }else{
220
+        } else{
221 221
             $filters[] = $route['filters'];
222 222
         }
223 223
 
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -44,20 +44,20 @@  discard block
 block discarded – undo
44 44
     {
45 45
         $this->lastReturn = null;
46 46
         
47
-		$url = (substr($url,0,1) !=='/' and strlen($url) > 0) ? "/{$url}" : $url;
47
+        $url = (substr($url,0,1) !=='/' and strlen($url) > 0) ? "/{$url}" : $url;
48 48
 
49
-    	foreach($this->routers as $key => $value){
50
-    		if( md5($this->prefix . $value['url'] . $value['protocol'] ) === md5( $url . $protocol ) ){
49
+        foreach($this->routers as $key => $value){
50
+            if( md5($this->prefix . $value['url'] . $value['protocol'] ) === md5( $url . $protocol ) ){
51 51
                 throw new Exception("There is already a route with the url {$url} and with the {$protocol} protocol configured.");
52 52
             }
53 53
         }
54 54
         
55 55
         $this->checkTypeRole($walking);
56 56
 
57
-		$route = [
58
-			'url' => $this->prefix.$url,
59
-			'role' => $walking,
60
-			'protocol' => $protocol,
57
+        $route = [
58
+            'url' => $this->prefix.$url,
59
+            'role' => $walking,
60
+            'protocol' => $protocol,
61 61
             'filters' => null,
62 62
             'where' => null,
63 63
             'before' => null,
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
             'after' => null,
66 66
             'afterAll' => $this->afterAll,
67 67
             'group' => self::getInstance()->group
68
-		];
68
+        ];
69 69
 
70
-		$this->routers[] = $route;		
70
+        $this->routers[] = $route;		
71 71
         
72 72
         return self::getInstance();
73 73
     }
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 
146 146
         $instance->getInstance()->byName($routeName);
147 147
 
148
-		$currentProtocol = $instance->getInstance()->getProtocol();
148
+        $currentProtocol = $instance->getInstance()->getProtocol();
149 149
 
150 150
         foreach(array_reverse($instance->getInstance()->routers) as $r => $route){
151 151
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
         
179 179
         $instance->getInstance()->currentRoute = null;
180 180
 
181
-	    throw new Exception('Page not found.',404);
181
+        throw new Exception('Page not found.',404);
182 182
     }
183 183
 
184 184
     public function filter($filters): Router
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-class Router{
7
+class Router {
8 8
     use Helper, CheckTrait, CheckWhere, DefinitionsTrait, ExtraJobsTrait;
9 9
 
10 10
     private static $instance = null;
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
     public static function create(): Router
27 27
     {
28
-        if(!self::getInstance()->instanced){
28
+        if (!self::getInstance()->instanced) {
29 29
             self::getInstance()->instanced = true;
30 30
         }
31 31
         
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
         return self::$instance;
39 39
     }
40 40
 
41
-    public function set($url ,$walking , string $protocol): Router
41
+    public function set($url, $walking, string $protocol): Router
42 42
     {
43 43
         $this->lastReturn = null;
44 44
         
45
-		$url = (substr($url,0,1) !=='/' and strlen($url) > 0) ? "/{$url}" : $url;
45
+		$url = (substr($url, 0, 1) !== '/' and strlen($url) > 0) ? "/{$url}" : $url;
46 46
 
47
-    	foreach($this->routers as $key => $value){
48
-    		if( md5($this->prefix . $value['url'] . $value['protocol'] ) === md5( $url . $protocol ) ){
47
+    	foreach ($this->routers as $key => $value) {
48
+    		if (md5($this->prefix.$value['url'].$value['protocol']) === md5($url.$protocol)) {
49 49
                 throw new Exception("There is already a route with the url {$url} and with the {$protocol} protocol configured.");
50 50
             }
51 51
         }
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
         return self::getInstance();
71 71
     }
72 72
 
73
-    public static function group(string $prefix,$callback): Router
73
+    public static function group(string $prefix, $callback): Router
74 74
     {
75
-        self::getInstance()->prefix = (substr($prefix,0,1) !== '/') ? "/{$prefix}" : $prefix;
75
+        self::getInstance()->prefix = (substr($prefix, 0, 1) !== '/') ? "/{$prefix}" : $prefix;
76 76
         self::getInstance()->group = sha1(date('d/m/Y h:m:i'));
77 77
         $callback();
78 78
         self::getInstance()->group = null;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 
84 84
     public static function where(): Router
85 85
     {
86
-        if(self::getInstance()->lastReturn){
86
+        if (self::getInstance()->lastReturn) {
87 87
             throw new Exception("It is not possible to define parameter tests for groups of routes.");
88 88
         }
89 89
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 
95 95
     public static function name(string $name): Router
96 96
     {
97
-        if(self::getInstance()->lastReturn){
97
+        if (self::getInstance()->lastReturn) {
98 98
             throw new Exception("There is no reason to call a {$name} route group.");
99 99
         }
100 100
 
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
 
103 103
         self::getInstance()->hasRouteName($name);
104 104
 
105
-        if(in_array($name,self::getInstance()->beforeExcepts)){
105
+        if (in_array($name, self::getInstance()->beforeExcepts)) {
106 106
             $currentRoute['beforeAll'] = null;
107 107
         }
108 108
 
109
-        if(in_array($name,self::getInstance()->afterExcepts)){
109
+        if (in_array($name, self::getInstance()->afterExcepts)) {
110 110
             $currentRoute['afterAll'] = null;
111 111
         }
112 112
 
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
 
120 120
     private function byName(?string $routName)
121 121
     {
122
-        if(!is_null($routName)){
122
+        if (!is_null($routName)) {
123 123
             $currentProtocol = $this->getProtocol();
124 124
 
125 125
             $this->checkName($routName);
126 126
     
127 127
             $route = $this->routers[$routName];
128 128
     
129
-            if(!$this->checkProtocol($route['protocol'], $currentProtocol)){
130
-                throw new Exception('Page not found.',404);
129
+            if (!$this->checkProtocol($route['protocol'], $currentProtocol)) {
130
+                throw new Exception('Page not found.', 404);
131 131
             }
132 132
     
133 133
             $this->checkFiltering($route);
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 
146 146
 		$currentProtocol = $instance->getInstance()->getProtocol();
147 147
 
148
-        foreach(array_reverse($instance->getInstance()->routers) as $r => $route){
148
+        foreach (array_reverse($instance->getInstance()->routers) as $r => $route) {
149 149
 
150 150
             $instance->getInstance()->currentRoute = $route;
151 151
 
152
-            if(!$instance->getInstance()->checkProtocol($route['protocol'], $currentProtocol)){
152
+            if (!$instance->getInstance()->checkProtocol($route['protocol'], $currentProtocol)) {
153 153
                 continue;
154 154
             }
155 155
 
@@ -159,11 +159,11 @@  discard block
 block discarded – undo
159 159
 
160 160
 
161 161
             $routs = $instance->getInstance()->explodeRoutes(
162
-                (substr($route['url'],strlen($route['url'])-1,1) === '/') , $route['url'],
163
-                (substr($_SERVER['REQUEST_URI'],strlen($_SERVER['REQUEST_URI'])-1,1) === '/') , $_SERVER['REQUEST_URI']
162
+                (substr($route['url'], strlen($route['url'])-1, 1) === '/'), $route['url'],
163
+                (substr($_SERVER['REQUEST_URI'], strlen($_SERVER['REQUEST_URI'])-1, 1) === '/'), $_SERVER['REQUEST_URI']
164 164
             );
165 165
 
166
-            if(!$instance->getInstance()->checkToHiking($route, $routs['routeRequest'], $routs['routeLoop'])){
166
+            if (!$instance->getInstance()->checkToHiking($route, $routs['routeRequest'], $routs['routeLoop'])) {
167 167
                 continue;
168 168
             }
169 169
 
@@ -176,18 +176,18 @@  discard block
 block discarded – undo
176 176
         
177 177
         $instance->getInstance()->currentRoute = null;
178 178
 
179
-	    throw new Exception('Page not found.',404);
179
+	    throw new Exception('Page not found.', 404);
180 180
     }
181 181
 
182 182
     public function filter($filters): Router
183 183
     {
184
-        if($this->lastReturn !== null){
184
+        if ($this->lastReturn !== null) {
185 185
             $currentGroup = end($this->routers)['group'];
186 186
 
187 187
             foreach ($this->routers as $key => $value) {
188 188
 
189
-                if($value['group'] === $currentGroup){
190
-                    $currentRoute = $this->addFilter($this->routers[$key],$filters);
189
+                if ($value['group'] === $currentGroup) {
190
+                    $currentRoute = $this->addFilter($this->routers[$key], $filters);
191 191
                     $this->routers[$key] = $currentRoute;
192 192
                 }
193 193
 
@@ -196,24 +196,24 @@  discard block
 block discarded – undo
196 196
             return $this;
197 197
         }
198 198
         
199
-        $this->routers[count($this->routers)-1] = $this->addFilter(end($this->routers),$filters);
199
+        $this->routers[count($this->routers)-1] = $this->addFilter(end($this->routers), $filters);
200 200
         return $this;
201 201
     }
202 202
 
203 203
     public static function addFilter(array $route, $filter): array
204 204
     {
205
-        if(is_null($route['filters'])){
205
+        if (is_null($route['filters'])) {
206 206
             $route['filters'] = $filter;
207 207
             return $route;
208 208
         }
209 209
 
210 210
         $filters = (is_array($filter)) ? $filter : [0 => $filter];
211 211
 
212
-        if(is_array($route['filters'])){
212
+        if (is_array($route['filters'])) {
213 213
             foreach ($route['filters'] as $key => $value) {
214 214
                 $filters[] = $value;
215 215
             }
216
-        }else{
216
+        }else {
217 217
             $filters[] = $route['filters'];
218 218
         }
219 219
 
Please login to merge, or discard this patch.
examples/index.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 /* NOTE: in case of error an exception is thrown */
11 11
 
12
-try{
12
+try {
13 13
     
14 14
     Router::dispatch();
15 15
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     /* Return current action route */
21 21
     $action = Router::currentRouteAction();
22 22
 
23
-}catch(Exception $er){
23
+}catch (Exception $er) {
24 24
 
25 25
     die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}.");
26 26
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
     /* Return current action route */
21 21
     $action = Router::currentRouteAction();
22 22
 
23
-}catch(Exception $er){
23
+} catch(Exception $er){
24 24
 
25 25
     die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}.");
26 26
 
Please login to merge, or discard this patch.
examples/Controllers/User.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use HnrAzevedo\Router\Controller;
6 6
 
7
-class User extends Controller{
7
+class User extends Controller {
8 8
 
9 9
     public function requereLogin($username, $password): void
10 10
     {
Please login to merge, or discard this patch.
examples/Filters/User.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,15 +4,15 @@
 block discarded – undo
4 4
 
5 5
 use HnrAzevedo\Filter\Filter as HnrFilter;
6 6
 
7
-class User extends HnrFilter{
7
+class User extends HnrFilter {
8 8
 
9 9
     public function user_in(): bool
10 10
     {
11
-        $this->addMessage('user_in','User required to be logged in.');
11
+        $this->addMessage('user_in', 'User required to be logged in.');
12 12
 
13
-        $this->addTreat('user_in','report_notLogged');
13
+        $this->addTreat('user_in', 'report_notLogged');
14 14
 
15
-        return (array_key_exists('user',$_SESSION));
15
+        return (array_key_exists('user', $_SESSION));
16 16
     }
17 17
 
18 18
     public function report_notLogged(): void
Please login to merge, or discard this patch.
src/Controller.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,14 +5,14 @@  discard block
 block discarded – undo
5 5
 use HnrAzevedo\Validator\Validator;
6 6
 use Exception;
7 7
 
8
-class Controller{
8
+class Controller {
9 9
     use Helper;
10 10
 
11 11
     protected array $fail = [];
12 12
 
13 13
     private function checkMethod(string $method): void
14 14
     {
15
-        if(!method_exists($this,$method)){
15
+        if (!method_exists($this, $method)) {
16 16
             throw new Exception("{$method} not found in ".get_class($this).".");
17 17
         }
18 18
     }
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
     {        
22 22
         $this->ValidateData();
23 23
 
24
-        if($this->checkFailData()){
24
+        if ($this->checkFailData()) {
25 25
             return false;
26 26
         }
27 27
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 
30 30
         $this->checkMethod($method);
31 31
 
32
-        call_user_func_array([$this,$method],  func_get_args());
32
+        call_user_func_array([$this, $method], func_get_args());
33 33
 
34 34
         return true;
35 35
     }
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
     {
39 39
         $valid = Validator::execute($this->getData()['POST']);
40 40
 
41
-        if(!$valid){
42
-            foreach(Validator::getErrors() as $err => $message){
41
+        if (!$valid) {
42
+            foreach (Validator::getErrors() as $err => $message) {
43 43
                 $this->fail[] = [
44 44
                     'input' => array_keys($message)[0],
45 45
                     'message' => $message[array_keys($message)[0]]
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
 
51 51
     private function checkFailData(): bool
52 52
     {
53
-        if(count($this->fail) > 0 ){
53
+        if (count($this->fail) > 0) {
54 54
             echo json_encode([
55 55
                 'error'=> $this->fail
56 56
             ]);
57 57
         }
58
-        return (count($this->fail) > 0 );
58
+        return (count($this->fail) > 0);
59 59
     }
60 60
 
61 61
 }
62 62
\ No newline at end of file
Please login to merge, or discard this patch.
src/Helper.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@
 block discarded – undo
50 50
     }
51 51
 
52 52
     protected function ControllerForm($controller, string $method, array $values){
53
-		$this->checkRole();
53
+        $this->checkRole();
54 54
         $method = ($method !== 'method') ? $method : $this->getData()['POST']['role'];
55 55
         $data = (array_key_exists('data',$values)) ? json_decode($values['data'], true) : null;
56 56
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 
78 78
         if( ($this->getProtocol() == 'form') ){
79 79
             $this->ControllerForm($controller, $method, $data['POST']);
80
-        }else {
80
+        } else {
81 81
             $data = (array_key_exists('data',$data['POST'])) ? json_decode($data['POST']['data'], true) : $data['GET'];
82 82
             call_user_func_array([$controller,$method],  $data);
83 83
         }
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         if($route[$state] !== null){
124 124
             if(is_string($route[$state])){
125 125
                 $this->Controller($route[$state]);
126
-            }else{
126
+            } else{
127 127
                 $route[$state]();
128 128
             }
129 129
         }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace HnrAzevedo\Router;
4 4
 
5
-trait Helper{
5
+trait Helper {
6 6
     use CheckTrait, ControllerTrait;
7 7
     
8 8
     private $currentRoute = null;
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     protected function getProtocol(): string
26 26
     {
27 27
         $protocol = ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')) ? 'ajax' : 'get';
28
-        $protocol = (array_key_existS('HTTP_REQUESTED_METHOD',$_SERVER)) ? strtolower($_SERVER['HTTP_REQUESTED_METHOD']) : $protocol;
28
+        $protocol = (array_key_existS('HTTP_REQUESTED_METHOD', $_SERVER)) ? strtolower($_SERVER['HTTP_REQUESTED_METHOD']) : $protocol;
29 29
             
30 30
         return $protocol;
31 31
     }
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
         ];
41 41
     }
42 42
 
43
-    protected function ControllerForm($controller, string $method, array $values){
43
+    protected function ControllerForm($controller, string $method, array $values) {
44 44
 		$this->checkRole();
45 45
         $method = ($method !== 'method') ? $method : $this->getData()['POST']['role'];
46
-        $data = (array_key_exists('data',$values)) ? json_decode($values['data'], true) : null;
46
+        $data = (array_key_exists('data', $values)) ? json_decode($values['data'], true) : null;
47 47
 
48
-        call_user_func_array([$controller,$method],  $data);
48
+        call_user_func_array([$controller, $method], $data);
49 49
     }
50 50
 
51 51
     protected function Controller(string $controll): void
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         $data = $this->getData();
54 54
 
55 55
         foreach ($data['GET'] as $name => $value) {
56
-            $controll = str_replace('{'.$name.'}',$value,$controll);
56
+            $controll = str_replace('{'.$name.'}', $value, $controll);
57 57
         }
58 58
 
59 59
         $this->checkControllsettable($controll);
@@ -62,30 +62,30 @@  discard block
 block discarded – undo
62 62
 
63 63
         $this->checkControllmethod($controll);
64 64
 
65
-        $controller = ucfirst(explode(':',$controll)[0]);
65
+        $controller = ucfirst(explode(':', $controll)[0]);
66 66
         $controller = new $controller();
67
-        $method = explode(':',$controll)[1];
67
+        $method = explode(':', $controll)[1];
68 68
 
69
-        if( ($this->getProtocol() == 'form') ){
69
+        if (($this->getProtocol() == 'form')) {
70 70
             $this->ControllerForm($controller, $method, $data['POST']);
71 71
         }else {
72
-            $data = (array_key_exists('data',$data['POST'])) ? json_decode($data['POST']['data'], true) : $data['GET'];
73
-            call_user_func_array([$controller,$method],  $data);
72
+            $data = (array_key_exists('data', $data['POST'])) ? json_decode($data['POST']['data'], true) : $data['GET'];
73
+            call_user_func_array([$controller, $method], $data);
74 74
         }
75 75
        
76 76
     }    
77 77
 
78
-    protected function explodeRoutes(bool $bar, string $url ,bool $bar_, string $url_): array
78
+    protected function explodeRoutes(bool $bar, string $url, bool $bar_, string $url_): array
79 79
     {   
80
-        $url = $bar ? substr($url, 0, -1) : $url ;
81
-        $url = explode('/',$url);
80
+        $url = $bar ? substr($url, 0, -1) : $url;
81
+        $url = explode('/', $url);
82 82
 
83
-        $url_ = $bar_ ? substr($url_, 0, -1) : $url_ ;
84
-        $url_ = explode('/',$url_);
83
+        $url_ = $bar_ ? substr($url_, 0, -1) : $url_;
84
+        $url_ = explode('/', $url_);
85 85
 
86
-        foreach($url as $ur => $u){
87
-            if(substr($u,0,2) === '{?'){
88
-                if(!array_key_exists($ur,$url_)){
86
+        foreach ($url as $ur => $u) {
87
+            if (substr($u, 0, 2) === '{?') {
88
+                if (!array_key_exists($ur, $url_)) {
89 89
                     $url_[$ur] = '';
90 90
                 };
91 91
             }
@@ -96,28 +96,28 @@  discard block
 block discarded – undo
96 96
 
97 97
     protected function toHiking(array $route)
98 98
     {
99
-        $this->callOnRoute($route,'beforeAll');
100
-        $this->callOnRoute($route,'before');
99
+        $this->callOnRoute($route, 'beforeAll');
100
+        $this->callOnRoute($route, 'before');
101 101
 
102
-        if(is_string($route['role'])){
102
+        if (is_string($route['role'])) {
103 103
             $this->Controller($route['role']);
104
-            $this->callOnRoute($route,'after');
105
-            $this->callOnRoute($route,'afterAll');
104
+            $this->callOnRoute($route, 'after');
105
+            $this->callOnRoute($route, 'afterAll');
106 106
             return true;
107 107
         }
108 108
 
109
-        call_user_func_array($route['role'],$this->getData()['GET']);
109
+        call_user_func_array($route['role'], $this->getData()['GET']);
110 110
 
111
-        $this->callOnRoute($route,'after');
112
-        $this->callOnRoute($route,'afterAll');
111
+        $this->callOnRoute($route, 'after');
112
+        $this->callOnRoute($route, 'afterAll');
113 113
     }
114 114
 
115
-    protected function callOnRoute(array $route,string $state)
115
+    protected function callOnRoute(array $route, string $state)
116 116
     {
117
-        if($route[$state] !== null){
118
-            if(is_string($route[$state])){
117
+        if ($route[$state] !== null) {
118
+            if (is_string($route[$state])) {
119 119
                 $this->Controller($route[$state]);
120
-            }else{
120
+            }else {
121 121
                 $route[$state]();
122 122
             }
123 123
         }
Please login to merge, or discard this patch.
src/DefinitionsTrait.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@
 block discarded – undo
2 2
 
3 3
 namespace HnrAzevedo\Router;
4 4
 
5
-trait DefinitionsTrait{
5
+trait DefinitionsTrait {
6 6
     private static $instance = null;
7 7
 
8 8
     public static function match(string $protocols, string $uri, $walking): Router
9 9
     {
10
-        foreach(explode('|',$protocols) as $protocol){
10
+        foreach (explode('|', $protocols) as $protocol) {
11 11
             self::getInstance()->add($uri, $walking, $protocol);
12 12
         }
13 13
         return self::$instance;
Please login to merge, or discard this patch.
src/ExtraJobsTrait.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -2,11 +2,11 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace HnrAzevedo\Router;
4 4
 
5
-trait ExtraJobsTrait{
5
+trait ExtraJobsTrait {
6 6
 
7 7
     public function before($walking): Router
8 8
     {
9
-        return $this->setOnRoute($walking,'before');
9
+        return $this->setOnRoute($walking, 'before');
10 10
     }
11 11
 
12 12
     public static function beforeAll($walking, $except = null): Router
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
         $excepts = is_array($except) ? $except : [$except];
15 15
         self::getInstance()->beforeExcepts = $excepts;
16 16
         self::getInstance()->beforeAll = $walking;
17
-        return self::getInstance()->setOnRoutes($walking,'beforeAll',$excepts);
17
+        return self::getInstance()->setOnRoutes($walking, 'beforeAll', $excepts);
18 18
     }
19 19
 
20 20
     public function after($walking): Router
21 21
     {
22
-        return $this->setOnRoute($walking,'after');
22
+        return $this->setOnRoute($walking, 'after');
23 23
     }
24 24
 
25 25
     public static function afterAll($walking, $except = null): Router
@@ -27,17 +27,17 @@  discard block
 block discarded – undo
27 27
         $excepts = is_array($except) ? $except : [$except];
28 28
         self::getInstance()->afterExcepts = $excepts;
29 29
         self::getInstance()->afterAll = $walking;
30
-        return self::getInstance()->setOnRoutes($walking,'afterAll',$excepts);
30
+        return self::getInstance()->setOnRoutes($walking, 'afterAll', $excepts);
31 31
     }
32 32
 
33 33
     private function setOnRoute($walking, string $state): Router
34 34
     {
35
-        if($this->lastReturn !== null){
35
+        if ($this->lastReturn !== null) {
36 36
             $currentGroup = end($this->routers)['group'];
37 37
 
38 38
             foreach ($this->routers as $key => $value) {
39 39
 
40
-                if($value['group'] === $currentGroup){
40
+                if ($value['group'] === $currentGroup) {
41 41
                     $this->routers[$key][$state] = $walking;
42 42
                 }
43 43
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 
52 52
     private function setOnRoutes($walking, string $state, array $excepts): Router
53 53
     {
54
-        foreach($this->routers as $r => $route){
55
-            if(!in_array($this->routers,$excepts)){
54
+        foreach ($this->routers as $r => $route) {
55
+            if (!in_array($this->routers, $excepts)) {
56 56
                 $this->routers[$r][$state] = $walking;
57 57
             }
58 58
         }
Please login to merge, or discard this patch.
src/CheckWhere.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -4,18 +4,18 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 
7
-trait CheckWhere{
7
+trait CheckWhere {
8 8
         
9 9
     protected function checkWhereParam($data)
10 10
     {
11
-        if(count($data) === 0){
11
+        if (count($data) === 0) {
12 12
             throw new Exception('It is necessary to define a condition to be tested.');
13 13
         }
14 14
     }
15 15
 
16 16
     protected function checkWhereParams($params)
17 17
     {
18
-        if(count($params) === 0){
18
+        if (count($params) === 0) {
19 19
             throw new Exception('The route in question has no parameters to be tested.');
20 20
         }
21 21
     }
@@ -24,24 +24,24 @@  discard block
 block discarded – undo
24 24
     {
25 25
         $pass = true;
26 26
 
27
-        if(!is_array($route['where'])){
27
+        if (!is_array($route['where'])) {
28 28
             return $pass;
29 29
         }
30 30
 
31
-        $routeURI = explode('/',$route['url']);
31
+        $routeURI = explode('/', $route['url']);
32 32
         $params = [];
33
-        foreach($routeURI as $p => $part){
34
-            if(!$this->isWhered($part,$request[$p])){
33
+        foreach ($routeURI as $p => $part) {
34
+            if (!$this->isWhered($part, $request[$p])) {
35 35
                 continue;
36 36
             }
37 37
                 
38
-            $param = substr(str_replace('?','',$part),1,-1);
38
+            $param = substr(str_replace('?', '', $part), 1, -1);
39 39
 
40
-            if(array_key_exists($param,$route['where'])){
40
+            if (array_key_exists($param, $route['where'])) {
41 41
                     
42 42
                 $params[$param] = $route['where'][$param];
43 43
 
44
-                if(!preg_match("/^{$params[$param]}$/",$request[$p])){
44
+                if (!preg_match("/^{$params[$param]}$/", $request[$p])) {
45 45
                     $pass = false;
46 46
                 }
47 47
             }
@@ -52,17 +52,17 @@  discard block
 block discarded – undo
52 52
 
53 53
     private function isWhered(string $part, string $value): bool
54 54
     {
55
-        return $this->isParameter($part) && !$this->checkParameterOptional($part,$value);
55
+        return $this->isParameter($part) && !$this->checkParameterOptional($part, $value);
56 56
     }
57 57
 
58 58
     private function checkParameterOptional(string $part, string $value): bool
59 59
     {
60
-        return substr($part,0,2) === '{?' && empty($value);
60
+        return substr($part, 0, 2) === '{?' && empty($value);
61 61
     }
62 62
 
63 63
     protected function isParameter(string $part): bool
64 64
     {
65
-        return (substr($part,0,1) === '{' && substr($part,-1) === '}');
65
+        return (substr($part, 0, 1) === '{' && substr($part, -1) === '}');
66 66
     }
67 67
 
68 68
     protected function callWhereAdd($data)
@@ -72,16 +72,16 @@  discard block
 block discarded – undo
72 72
         $data = (count($data) > 1) ? [$data[0] => $data[1]] : $data[0];
73 73
         
74 74
         $route = end($this->routers);
75
-        $routeURI = explode('/',$route['url']);
75
+        $routeURI = explode('/', $route['url']);
76 76
         $params = [];
77
-        foreach($routeURI as $part){
78
-            if(!$this->isParameter($part)){
77
+        foreach ($routeURI as $part) {
78
+            if (!$this->isParameter($part)) {
79 79
                 continue;
80 80
             }
81 81
             
82
-            $param = substr(str_replace('?','',$part),1,-1);
82
+            $param = substr(str_replace('?', '', $part), 1, -1);
83 83
 
84
-            if(array_key_exists($param,$data)){
84
+            if (array_key_exists($param, $data)) {
85 85
                 $params[$param] = $data[$param];
86 86
             }
87 87
                 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 
90 90
         $this->checkWhereParams($params);
91 91
 
92
-        $route['where'] = (is_array($route['where'])) ? array_merge($route['where'],$params) : $params;
92
+        $route['where'] = (is_array($route['where'])) ? array_merge($route['where'], $params) : $params;
93 93
 
94 94
         $this->routers[count($this->routers)-1] = $route;
95 95
     }
Please login to merge, or discard this patch.