Passed
Push — master ( 165fd0...1f77d5 )
by Henri
01:33
created
src/RunInTrait.php 1 patch
Spacing   +26 added lines, -26 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
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
         $this->beforeAll = (!isset($this->beforeAll)) ? function() {} : $this->beforeAll;
21 21
         $this->afterAll = (!isset($this->afterAll)) ? function() {} : $this->afterAll;
22 22
         
23
-        if($state === 'before'){
23
+        if ($state === 'before') {
24 24
             return ($except) ? $this->beforeExcepts : $this->beforeAll;
25 25
         }
26 26
 
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 
30 30
     protected function setState(string $state, $settable, bool $except = false): bool
31 31
     {
32
-        if($state === 'before'){
33
-            if($except){
32
+        if ($state === 'before') {
33
+            if ($except) {
34 34
                 $this->beforeExcepts = $settable;
35 35
                 return true;
36 36
             }
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
             return true;
40 40
         }
41 41
 
42
-        if($except){
42
+        if ($except) {
43 43
             $this->afterExcepts = $settable;
44 44
             return true;
45 45
         }
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
60 60
 
61 61
     public static function beforeAll($closure, ?array $excepts = null): RouterInterface
62 62
     {
63
-        self::getInstance()->setState('before', (is_array($excepts)) ? $excepts : [] ,true);
63
+        self::getInstance()->setState('before', (is_array($excepts)) ? $excepts : [], true);
64 64
         self::getInstance()->setState('before', $closure, false);
65 65
         return self::getInstance();
66 66
     }
67 67
 
68 68
     public static function afterAll($closure, ?array $excepts = null): RouterInterface
69 69
     {
70
-        self::getInstance()->setState('after', (is_array($excepts)) ? $excepts : [] ,true);
70
+        self::getInstance()->setState('after', (is_array($excepts)) ? $excepts : [], true);
71 71
         self::getInstance()->setState('after', $closure, false);
72 72
         return self::getInstance();
73 73
     }
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 
85 85
     protected function executeRouteAction($action): bool
86 86
     {
87
-        if(is_callable($action)){        
87
+        if (is_callable($action)) {        
88 88
             call_user_func_array($action, $_REQUEST);
89 89
             return true;
90 90
         }
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
         $excepts = (is_array($excepts)) ? $excepts : [];
100 100
         $group = self::getInstance()->inSave()['group'];
101 101
 
102
-        foreach(self::getInstance()->getRoutes() as $r => $route){
103
-            if($route['group'] === $group && !in_array($r, $excepts)){
104
-                self::getInstance()->getRoutes()[$r][$state] = (is_null($route[$state])) ? [ $closure ] : array_merge($route[$state], [ $closure ]); 
102
+        foreach (self::getInstance()->getRoutes() as $r => $route) {
103
+            if ($route['group'] === $group && !in_array($r, $excepts)) {
104
+                self::getInstance()->getRoutes()[$r][$state] = (is_null($route[$state])) ? [$closure] : array_merge($route[$state], [$closure]); 
105 105
             }
106 106
         }
107 107
 
@@ -111,14 +111,14 @@  discard block
 block discarded – undo
111 111
     private static function addInRoute(string $state, $closure): RouterInterface
112 112
     {
113 113
         $route = self::getInstance()->inSave();
114
-        $route[$state] = (!is_null($route[$state])) ? [ $closure ] : array_merge($route[$state], [ $closure ]);
115
-        self::updateRoute($route,array_key_last(self::getInstance()->getRoutes()));
114
+        $route[$state] = (!is_null($route[$state])) ? [$closure] : array_merge($route[$state], [$closure]);
115
+        self::updateRoute($route, array_key_last(self::getInstance()->getRoutes()));
116 116
         return self::getInstance();
117 117
     }
118 118
 
119 119
     protected function executeBefore(): void
120 120
     {
121
-        if(!in_array($this->currentName(), (array) $this->getState('before', true))){
121
+        if (!in_array($this->currentName(), (array) $this->getState('before', true))) {
122 122
             ($this->getState('before', false))();
123 123
         }
124 124
 
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
     {
130 130
         $this->executeState('after');
131 131
 
132
-        if(!in_array($this->currentName(), (array) $this->getState('after', true))){
132
+        if (!in_array($this->currentName(), (array) $this->getState('after', true))) {
133 133
             ($this->getState('after', false))();
134 134
         }
135 135
     }
136 136
 
137 137
     private function executeState(string $stage): void
138 138
     {
139
-        foreach($this->current()[$stage] as $state){
140
-            if(is_callable($state)){
139
+        foreach ($this->current()[$stage] as $state) {
140
+            if (is_callable($state)) {
141 141
                 $state();
142 142
                 continue;
143 143
             }
@@ -148,31 +148,31 @@  discard block
 block discarded – undo
148 148
 
149 149
     private function executeController(string $controllerMeth): void
150 150
     {
151
-        if(count(explode('@',$controllerMeth)) !== 2){
151
+        if (count(explode('@', $controllerMeth)) !== 2) {
152 152
             $path = urldecode($this->current()['uri']->getPath());
153 153
             throw new \RuntimeException("Misconfigured route action ({$path})");
154 154
         }
155 155
 
156
-        $controller = (string) explode('@',$controllerMeth)[0];
157
-        $method = (string) explode('@',$controllerMeth)[1];
156
+        $controller = (string) explode('@', $controllerMeth)[0];
157
+        $method = (string) explode('@', $controllerMeth)[1];
158 158
 
159 159
         $this->checkControllerMeth($controllerMeth);
160 160
 
161
-        call_user_func_array([(new $controller()),$method], $_REQUEST);
161
+        call_user_func_array([(new $controller()), $method], $_REQUEST);
162 162
     }
163 163
 
164 164
     private function checkControllerMeth(string $controllerMeth): void
165 165
     {
166
-        $routeURI = str_replace(['{:','{','}'],'',urldecode($this->current()['uri']->getPath()));
166
+        $routeURI = str_replace(['{:', '{', '}'], '', urldecode($this->current()['uri']->getPath()));
167 167
 
168
-        $controller = (string) explode('@',$controllerMeth)[0];
169
-        $method = (string) explode('@',$controllerMeth)[1];
168
+        $controller = (string) explode('@', $controllerMeth)[0];
169
+        $method = (string) explode('@', $controllerMeth)[1];
170 170
 
171
-        if(!class_exists($controller)){
171
+        if (!class_exists($controller)) {
172 172
             throw new \RuntimeException("Controller not found in route URI {$routeURI}");
173 173
         }
174 174
 
175
-        if(!method_exists($controller, $method)){
175
+        if (!method_exists($controller, $method)) {
176 176
             throw new \RuntimeException("Method {$method} not found in controller {$controller} in route URI {$routeURI}");
177 177
         }
178 178
         
Please login to merge, or discard this patch.