Passed
Branch master (7482d2)
by Henri
09:41 queued 08:07
created
src/CheckTrait.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace HnrAzevedo\Router;
6 6
 
@@ -12,28 +12,28 @@  discard block
 block discarded – undo
12 12
     
13 13
     protected function hasRouteName(string $name): void
14 14
     {
15
-        if(!isset($this->routesName[$name])){
15
+        if (!isset($this->routesName[$name])) {
16 16
             throw new \RuntimeException("There is no route named with {$name}");
17 17
         }
18 18
     }
19 19
 
20 20
     protected function isInNameGroup(): void
21 21
     {
22
-        if(!is_null($this->getGroup())){
22
+        if (!is_null($this->getGroup())) {
23 23
             throw new \RuntimeException("It is not allowed to assign names to groups");
24 24
         }
25 25
     }
26 26
 
27 27
     protected function isInPseudGroup(): void
28 28
     {
29
-        if(!is_null($this->getGroup())){
29
+        if (!is_null($this->getGroup())) {
30 30
             throw new \RuntimeException("To assign actions before or after the execution of the route, use beforeGroup or afterGroup");
31 31
         }
32 32
     }
33 33
 
34 34
     protected function existRouteName(string $name): void
35 35
     {
36
-        if(isset($this->routesName[$name])){
36
+        if (isset($this->routesName[$name])) {
37 37
             throw new \RuntimeException("There is already a route named with {$name}");
38 38
         }
39 39
     }
@@ -41,19 +41,19 @@  discard block
 block discarded – undo
41 41
     protected function checkMethod(array $route, $method): void
42 42
     {
43 43
         $hasMethod = false;
44
-        foreach(explode('|',$route['method']) as $routeMethod){
45
-            if(@preg_match("/{$routeMethod}/",$method) !== 0 || $method === '*'){
44
+        foreach (explode('|', $route['method']) as $routeMethod) {
45
+            if (@preg_match("/{$routeMethod}/", $method) !== 0 || $method === '*') {
46 46
                 $hasMethod = true;
47 47
             }
48 48
         }
49
-        if(!$hasMethod){
49
+        if (!$hasMethod) {
50 50
             throw new \Exception('This route is not released for the accessed method');
51 51
         } 
52 52
     }
53 53
 
54 54
     protected function throwCallable($value): void
55 55
     {
56
-        if(is_callable($value)){
56
+        if (is_callable($value)) {
57 57
             throw new \Exception('Passing functions as attributes is not allowed');
58 58
         }
59 59
     }
Please login to merge, or discard this patch.
src/Router.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace HnrAzevedo\Router;
6 6
 
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     {
35 35
         $route = self::getInstance()->inSave();
36 36
 
37
-        if(null === $value){
37
+        if (null === $value) {
38 38
             return (isset($route['attributes'][$name])) ? $route['attributes'][$name] : null;
39 39
         }
40 40
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     public static function group(string $prefix, \Closure $closure): Router
48 48
     {
49 49
         $id = sha1(date('d/m/Y h:m:i'));
50
-        while(array_key_exists($id, self::getInstance()->groupsName)){
50
+        while (array_key_exists($id, self::getInstance()->groupsName)) {
51 51
             $id = sha1(date('d/m/Y h:m:i').$id);
52 52
         }
53 53
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     {
69 69
         self::getInstance()->loaded = true;
70 70
 
71
-        if(null !== $name){
71
+        if (null !== $name) {
72 72
             return self::getInstance()->loadByName($name);
73 73
         }
74 74
 
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
 
77 77
         $requestMethod = (isset($_REQUEST['REQUEST_METHOD'])) ? $_REQUEST['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD'];
78 78
 
79
-        foreach(self::getInstance()->getRoutes() as $r => $route){
79
+        foreach (self::getInstance()->getRoutes() as $r => $route) {
80 80
             self::getInstance()->currentRoute = $route;
81 81
             self::getInstance()->currentRoute['name'] = $r;
82 82
 
83
-            try{
83
+            try {
84 84
                 self::getInstance()->checkMethod($route, $requestMethod);
85 85
                 self::getInstance()->checkData($route, (new Uri($_SERVER['REQUEST_URI']))->getPath());
86 86
                 return self::getInstance();
87
-            }catch(\Exception $er){
87
+            }catch (\Exception $er) {
88 88
                 continue;
89 89
             }
90 90
         }
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
     public static function run(?string $name = null): RouterInterface
100 100
     {
101
-        if(!self::getInstance()->loaded){
101
+        if (!self::getInstance()->loaded) {
102 102
             self::getInstance()->load($name);
103 103
         }
104 104
 
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
 
109 109
         self::getInstance()->executeBefore();
110 110
         
111
-        try{
111
+        try {
112 112
             $action = unserialize(self::getInstance()->current()['action']);
113
-            self::getInstance()->executeRouteAction( (is_string($action)) ? $action : $action->getClosure()  );
114
-        }catch(\Exception $er){
113
+            self::getInstance()->executeRouteAction((is_string($action)) ? $action : $action->getClosure());
114
+        }catch (\Exception $er) {
115 115
             self::getInstance()->error = $er;
116 116
         }
117 117
         
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 
125 125
     private function checkError(): void
126 126
     {
127
-        if(isset($this->error)){
127
+        if (isset($this->error)) {
128 128
             throw $this->error;
129 129
         }
130 130
     }
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 
139 139
     public static function routes(?array $routes = null): array
140 140
     {
141
-        if(null !== $routes){
141
+        if (null !== $routes) {
142 142
             self::getInstance()->setRoutes($routes);
143 143
             self::getInstance()->sortRoutes();
144 144
         }
Please login to merge, or discard this patch.