Completed
Push — master ( 9e523e...7fc7d9 )
by Anderson
02:05
created
src/Core/Route.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
             $customRegex = FALSE;
570 570
             foreach ($replaces as $regex => $replace)
571 571
             {
572
-                if($customRegex)
572
+                if ($customRegex)
573 573
                     continue;
574 574
 
575 575
                 $matches = [];
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
                 $c = 0;
583 583
                 $segment = preg_replace('/'.$regex.'/', $replace, $segment, 1, $c);
584 584
 
585
-                if( $regex == array_keys($replaces)[0] && $c > 0)
585
+                if ($regex == array_keys($replaces)[0] && $c > 0)
586 586
                     $customRegex = TRUE;
587 587
             }
588 588
         }
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
                             {
1016 1016
                                 for ($i = 0; $i < count($e_findPath); $i++)
1017 1017
                                 {
1018
-                                    if(in_array($i, $skip_seg))
1018
+                                    if (in_array($i, $skip_seg))
1019 1019
                                         continue;
1020 1020
 
1021 1021
                                     if ($valid)
Please login to merge, or discard this patch.
Braces   +120 added lines, -90 removed lines patch added patch discarded remove patch
@@ -146,11 +146,13 @@  discard block
 block discarded – undo
146 146
         $controller = $parsedController[1];
147 147
         $method     = $parsedController[2];
148 148
 
149
-        if (!is_string($path))
150
-            show_error('Route path must be a string ', 500, 'Route error: bad route path');
149
+        if (!is_string($path)) {
150
+                    show_error('Route path must be a string ', 500, 'Route error: bad route path');
151
+        }
151 152
 
152
-        if (!is_string($verb))
153
-            show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type');
153
+        if (!is_string($verb)) {
154
+                    show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type');
155
+        }
154 156
 
155 157
         $verb = strtoupper($verb);
156 158
 
@@ -186,30 +188,36 @@  discard block
 block discarded – undo
186 188
         $route['prefix'] = NULL;
187 189
         $group_prefix = implode('/', self::$prefix);
188 190
 
189
-        if ($group_prefix)
190
-            $route['prefix'] = $group_prefix.'/';
191
+        if ($group_prefix) {
192
+                    $route['prefix'] = $group_prefix.'/';
193
+        }
191 194
 
192
-        if (isset($attr['prefix']))
193
-            $route['prefix'] .= $attr['prefix'];
195
+        if (isset($attr['prefix'])) {
196
+                    $route['prefix'] .= $attr['prefix'];
197
+        }
194 198
 
195 199
         // Setting up the namespace
196 200
 
197 201
         $route['namespace'] = NULL;
198 202
         $group_namespace = implode('/', self::$namespace);
199 203
 
200
-        if (!is_null($group_namespace))
201
-            $route['namespace'] = $group_namespace.'/';
202
-        if (isset($attr['namespace']))
203
-            $route['namespace'] .= $attr['namespace'];
204
+        if (!is_null($group_namespace)) {
205
+                    $route['namespace'] = $group_namespace.'/';
206
+        }
207
+        if (isset($attr['namespace'])) {
208
+                    $route['namespace'] .= $attr['namespace'];
209
+        }
204 210
 
205 211
         $route['prefix']    = trim($route['prefix'], '/');
206 212
         $route['namespace'] = trim($route['namespace'], '/');
207 213
 
208
-        if (empty($route['prefix']))
209
-            $route['prefix'] = NULL;
214
+        if (empty($route['prefix'])) {
215
+                    $route['prefix'] = NULL;
216
+        }
210 217
 
211
-        if (empty($route['namespace']))
212
-            $route['namespace'] = NULL;
218
+        if (empty($route['namespace'])) {
219
+                    $route['namespace'] = NULL;
220
+        }
213 221
 
214 222
         // Route middleware
215 223
         $route['middleware'] = [];
@@ -219,14 +227,14 @@  discard block
 block discarded – undo
219 227
         {
220 228
             if (is_array($attr['middleware']))
221 229
             {
222
-                foreach ($attr['middleware'] as $middleware)
223
-                    $route['middleware'][] = $middleware; # Group
224
-            }
225
-            elseif (is_string($attr['middleware']))
230
+                foreach ($attr['middleware'] as $middleware) {
231
+                                    $route['middleware'][] = $middleware;
232
+                }
233
+                # Group
234
+            } elseif (is_string($attr['middleware']))
226 235
             {
227 236
                 $route['middleware'][] = $attr['middleware']; # Group
228
-            }
229
-            else
237
+            } else
230 238
             {
231 239
                 show_error('Route middleware must be a string or an array', 500, 'Route error: bad middleware format');
232 240
             }
@@ -398,8 +406,9 @@  discard block
 block discarded – undo
398 406
      */
399 407
     public static function matches($verbs, $url, $attr, $hideOriginal = FALSE)
400 408
     {
401
-        if (!is_array($verbs))
402
-            show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list');
409
+        if (!is_array($verbs)) {
410
+                    show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list');
411
+        }
403 412
 
404 413
         foreach ($verbs as $verb)
405 414
         {
@@ -427,19 +436,23 @@  discard block
 block discarded – undo
427 436
 
428 437
         $hideOriginal = FALSE;
429 438
 
430
-        if (isset($attr['namespace']))
431
-            $base_attr['namespace']  = $attr['namespace'];
439
+        if (isset($attr['namespace'])) {
440
+                    $base_attr['namespace']  = $attr['namespace'];
441
+        }
432 442
 
433
-        if (isset($attr['middleware']))
434
-            $base_attr['middleware'] = $attr['middleware'];
443
+        if (isset($attr['middleware'])) {
444
+                    $base_attr['middleware'] = $attr['middleware'];
445
+        }
435 446
 
436
-        if (isset($attr['hideOriginal']))
437
-            $hideOriginal = (bool) $attr['hideOriginal'];
447
+        if (isset($attr['hideOriginal'])) {
448
+                    $hideOriginal = (bool) $attr['hideOriginal'];
449
+        }
438 450
 
439 451
         $base_attr['prefix'] = strtolower($name);
440 452
 
441
-        if (isset($attr['prefix']))
442
-            $base_attr['prefix'] = $attr['prefix'];
453
+        if (isset($attr['prefix'])) {
454
+                    $base_attr['prefix'] = $attr['prefix'];
455
+        }
443 456
 
444 457
         $only = [];
445 458
 
@@ -450,8 +463,7 @@  discard block
 block discarded – undo
450 463
             if (is_array($attr['only']))
451 464
             {
452 465
                 $only = $attr['only'];
453
-            }
454
-            else
466
+            } else
455 467
             {
456 468
                 $only[] = $attr['only'];
457 469
             }
@@ -528,13 +540,15 @@  discard block
 block discarded – undo
528 540
 
529 541
         $path = $route->path;
530 542
 
531
-        if (!is_null($prefix))
532
-            $path = $prefix.'/'.$path;
543
+        if (!is_null($prefix)) {
544
+                    $path = $prefix.'/'.$path;
545
+        }
533 546
 
534 547
         $controller = $route->controller.'/'.$route->method;
535 548
 
536
-        if (!is_null($namespace))
537
-            $controller = $namespace.'/'.$controller;
549
+        if (!is_null($namespace)) {
550
+                    $controller = $namespace.'/'.$controller;
551
+        }
538 552
 
539 553
         $path       = trim($path, '/');
540 554
         $controller = trim($controller, '/');
@@ -569,8 +583,9 @@  discard block
 block discarded – undo
569 583
             $customRegex = FALSE;
570 584
             foreach ($replaces as $regex => $replace)
571 585
             {
572
-                if($customRegex)
573
-                    continue;
586
+                if($customRegex) {
587
+                                    continue;
588
+                }
574 589
 
575 590
                 $matches = [];
576 591
 
@@ -582,8 +597,9 @@  discard block
 block discarded – undo
582 597
                 $c = 0;
583 598
                 $segment = preg_replace('/'.$regex.'/', $replace, $segment, 1, $c);
584 599
 
585
-                if( $regex == array_keys($replaces)[0] && $c > 0)
586
-                    $customRegex = TRUE;
600
+                if( $regex == array_keys($replaces)[0] && $c > 0) {
601
+                                    $customRegex = TRUE;
602
+                }
587 603
             }
588 604
         }
589 605
 
@@ -601,11 +617,11 @@  discard block
 block discarded – undo
601 617
             {
602 618
                 $args['optional'][] = $arg;
603 619
                 $argConstraint = TRUE;
604
-            }
605
-            else
620
+            } else
606 621
             {
607
-                if ($argConstraint)
608
-                    show_error('Optional route path argument not valid at this position', 500, 'Route error');
622
+                if ($argConstraint) {
623
+                                    show_error('Optional route path argument not valid at this position', 500, 'Route error');
624
+                }
609 625
                 $args['required'][] = $arg;
610 626
             }
611 627
         }
@@ -715,12 +731,14 @@  discard block
 block discarded – undo
715 731
             $path = key($route);
716 732
             $_404 = $route[$path];
717 733
 
718
-            if (!isset($routes[$path]))
719
-                $routes[$path] = $_404;
734
+            if (!isset($routes[$path])) {
735
+                            $routes[$path] = $_404;
736
+            }
720 737
         }
721 738
 
722
-        if (is_null(self::$defaultController))
723
-            show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
739
+        if (is_null(self::$defaultController)) {
740
+                    show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
741
+        }
724 742
 
725 743
         $defaultController = self::$defaultController->compiled;
726 744
         $defaultController = $defaultController[key($defaultController)];
@@ -754,11 +772,13 @@  discard block
 block discarded – undo
754 772
      */
755 773
     public static function group($attr, $routes)
756 774
     {
757
-        if (!is_array($attr))
758
-            show_error('Group attribute must be a valid array');
775
+        if (!is_array($attr)) {
776
+                    show_error('Group attribute must be a valid array');
777
+        }
759 778
 
760
-        if (!isset($attr['prefix']))
761
-            show_error('You must specify an prefix!');
779
+        if (!isset($attr['prefix'])) {
780
+                    show_error('You must specify an prefix!');
781
+        }
762 782
 
763 783
         self::$prefix[] = $attr['prefix'];
764 784
 
@@ -781,15 +801,14 @@  discard block
 block discarded – undo
781 801
             {
782 802
                 if (is_array($attr['middleware']) && !empty($attr['middleware']))
783 803
                 {
784
-                    foreach ($attr['middleware'] as $middleware)
785
-                        self::$middleware[] = $middleware;
786
-                }
787
-                else
804
+                    foreach ($attr['middleware'] as $middleware) {
805
+                                            self::$middleware[] = $middleware;
806
+                    }
807
+                } else
788 808
                 {
789 809
                     self::$middleware[] = $attr['middleware'];
790 810
                 }
791
-            }
792
-            else
811
+            } else
793 812
             {
794 813
                 show_error('Group middleware must be an array o a string', 500, 'Route error');
795 814
             }
@@ -821,14 +840,17 @@  discard block
 block discarded – undo
821 840
                 'as'   => $as
822 841
             ];
823 842
 
824
-        if (!is_null($attr) && !is_array($attr))
825
-            show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type');
843
+        if (!is_null($attr) && !is_array($attr)) {
844
+                    show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type');
845
+        }
826 846
 
827
-        if (!is_null($attr))
828
-            $routeAttr = array_merge($routeAttr, $attr);
847
+        if (!is_null($attr)) {
848
+                    $routeAttr = array_merge($routeAttr, $attr);
849
+        }
829 850
 
830
-        if (isset($attr['prefix']))
831
-            show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed');
851
+        if (isset($attr['prefix'])) {
852
+                    show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed');
853
+        }
832 854
 
833 855
         self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as], TRUE, TRUE);
834 856
     }
@@ -847,14 +869,14 @@  discard block
 block discarded – undo
847 869
         if (is_null($verb))
848 870
         {
849 871
             return self::$routes;
850
-        }
851
-        else
872
+        } else
852 873
         {
853 874
             $routes = [];
854 875
             foreach (self::$routes as $route)
855 876
             {
856
-                if ($route->verb == $verb)
857
-                    $routes[] = $route;
877
+                if ($route->verb == $verb) {
878
+                                    $routes[] = $route;
879
+                }
858 880
             }
859 881
             return $routes;
860 882
         }
@@ -951,18 +973,21 @@  discard block
 block discarded – undo
951 973
      */
952 974
     public static function getRouteByPath($path, $requestMethod = NULL)
953 975
     {
954
-        if (is_null($requestMethod))
955
-            $requestMethod = $_SERVER['REQUEST_METHOD'];
976
+        if (is_null($requestMethod)) {
977
+                    $requestMethod = $_SERVER['REQUEST_METHOD'];
978
+        }
956 979
 
957 980
         $routes = self::getRoutes($requestMethod);
958 981
 
959
-        if (empty($routes))
960
-            return FALSE;
982
+        if (empty($routes)) {
983
+                    return FALSE;
984
+        }
961 985
 
962 986
         $path = trim($path);
963 987
 
964
-        if ($path == '')
965
-            return self::$defaultController;
988
+        if ($path == '') {
989
+                    return self::$defaultController;
990
+        }
966 991
 
967 992
         $wildcards =
968 993
             [
@@ -988,10 +1013,10 @@  discard block
 block discarded – undo
988 1013
 
989 1014
                     if ($mode == 'exact')
990 1015
                     {
991
-                        if ($findPath == $compiledPath)
992
-                            return $route;
993
-                    }
994
-                    else
1016
+                        if ($findPath == $compiledPath) {
1017
+                                                    return $route;
1018
+                        }
1019
+                    } else
995 1020
                     {
996 1021
                         $e_findPath     = explode('/', $findPath);
997 1022
                         $e_compiledPath = explode('/', $compiledPath);
@@ -1007,24 +1032,28 @@  discard block
 block discarded – undo
1007 1032
                                 $reg   = preg_replace($wildcards, $replaces, $e_compiledPath[$i], -1, $count);
1008 1033
                                 $valid = (bool) preg_match('#^'.$reg.'$#', $e_findPath[$i]);
1009 1034
 
1010
-                                if ($valid && $count > 0)
1011
-                                    $skip_seg[] = $i;
1035
+                                if ($valid && $count > 0) {
1036
+                                                                    $skip_seg[] = $i;
1037
+                                }
1012 1038
                             }
1013 1039
 
1014 1040
                             if ($valid)
1015 1041
                             {
1016 1042
                                 for ($i = 0; $i < count($e_findPath); $i++)
1017 1043
                                 {
1018
-                                    if(in_array($i, $skip_seg))
1019
-                                        continue;
1044
+                                    if(in_array($i, $skip_seg)) {
1045
+                                                                            continue;
1046
+                                    }
1020 1047
 
1021
-                                    if ($valid)
1022
-                                        $valid = $e_findPath[$i] == $e_compiledPath[$i];
1048
+                                    if ($valid) {
1049
+                                                                            $valid = $e_findPath[$i] == $e_compiledPath[$i];
1050
+                                    }
1023 1051
                                 }
1024 1052
                             }
1025 1053
 
1026
-                            if ($valid)
1027
-                                return $route;
1054
+                            if ($valid) {
1055
+                                                            return $route;
1056
+                            }
1028 1057
                         }
1029 1058
                     }
1030 1059
                 }
@@ -1058,8 +1087,9 @@  discard block
 block discarded – undo
1058 1087
 
1059 1088
         for ($s = 0; $s < count($r_seg); $s++)
1060 1089
         {
1061
-            if (!isset($p_seg[$s]))
1062
-                continue;
1090
+            if (!isset($p_seg[$s])) {
1091
+                            continue;
1092
+            }
1063 1093
 
1064 1094
             if ($r_seg[$s] != $p_seg[$s])
1065 1095
             {
Please login to merge, or discard this patch.