Completed
Push — master ( 243da4...c390c3 )
by Siro Díaz
02:29
created
Routify/RouterParser.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
      */
66 66
 
67 67
     public function countParams($pattern) {
68
-        if($this->hasParams($pattern) === false) {
68
+        if ($this->hasParams($pattern) === false) {
69 69
             return 0;
70 70
         }
71 71
 
72 72
         $pattern = str_split($pattern); // split string in characters
73 73
         $totalParams = 0;
74
-        for($i = 0; $i < count($pattern); $i++) {
75
-            if($pattern[$i] === self::PARAMETER_IDENTIFIER) {
74
+        for ($i = 0; $i < count($pattern); $i++) {
75
+            if ($pattern[$i] === self::PARAMETER_IDENTIFIER) {
76 76
                 $totalParams++;
77 77
             }
78 78
         }
@@ -90,15 +90,15 @@  discard block
 block discarded – undo
90 90
      */
91 91
 
92 92
     public function getParams($pattern) {
93
-        if(!$this->hasParams($pattern)) {
93
+        if (!$this->hasParams($pattern)) {
94 94
             return [];
95 95
         }
96 96
 
97 97
         $pattern = explode('/', $pattern);
98 98
         $path = explode('/', $this->path);
99 99
         $params = [];
100
-        for($i = 0; $i < count($pattern); $i++) {
101
-            if(strpos($pattern[$i], self::PARAMETER_IDENTIFIER) !== false) {
100
+        for ($i = 0; $i < count($pattern); $i++) {
101
+            if (strpos($pattern[$i], self::PARAMETER_IDENTIFIER) !== false) {
102 102
                 $params[substr($pattern[$i], 1)] = $path[$i];
103 103
             }
104 104
         }
@@ -117,20 +117,20 @@  discard block
 block discarded – undo
117 117
         $pattern = explode('/', $pattern);
118 118
         $path = explode('/', $this->path);
119 119
 
120
-        if(count($pattern) !== count($path)) {
120
+        if (count($pattern) !== count($path)) {
121 121
             return false;
122 122
         }
123 123
 
124 124
         $found = true;
125 125
         $index = 0;
126
-        while($found && $index < count($pattern)) {
126
+        while ($found && $index < count($pattern)) {
127 127
             $check = true;
128
-            if(strpos($pattern[$index], self::PARAMETER_IDENTIFIER) !== false) {
128
+            if (strpos($pattern[$index], self::PARAMETER_IDENTIFIER) !== false) {
129 129
                 $check = false;
130 130
             }
131 131
 
132
-            if($check) {
133
-                if (!preg_match('/^'. $pattern[$index] .'$/', $path[$index])) {
132
+            if ($check) {
133
+                if (!preg_match('/^'.$pattern[$index].'$/', $path[$index])) {
134 134
                     $found = false;
135 135
                 }
136 136
             }
Please login to merge, or discard this patch.
Routify/Router.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
         $found = false;
105 105
         $counter = 0;
106 106
 
107
-        if(count($this->routes) === 0) {
107
+        if (count($this->routes) === 0) {
108 108
             return $found;
109 109
         }
110 110
 
111
-        while($found === false && $counter < count($this->routes)) {
112
-            if($this->routes[$counter]->getUri() === $uri && $this->routes[$counter]->getMethod() === $method) {
111
+        while ($found === false && $counter < count($this->routes)) {
112
+            if ($this->routes[$counter]->getUri() === $uri && $this->routes[$counter]->getMethod() === $method) {
113 113
                 $found = true;
114 114
             }
115 115
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
 
131 131
     private function addRoute($uri, $method, $response, array $middleware = []) {
132
-        if($this->find($uri, $method)) {    // search if exists an apparition
132
+        if ($this->find($uri, $method)) {    // search if exists an apparition
133 133
             return false;
134 134
         }
135 135
 
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
      */
213 213
 
214 214
     public function both($uri, $response, $methods = Method::GET, array $middleware = []) {
215
-        if(is_array($methods)) {
216
-            foreach($methods as $method) {
215
+        if (is_array($methods)) {
216
+            foreach ($methods as $method) {
217 217
                 $this->addRoute($uri, $method, $response, $middleware);
218 218
             }
219 219
         } else {
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      */
229 229
 
230 230
     public function notFound($func) {
231
-        if(is_callable($func)) {
231
+        if (is_callable($func)) {
232 232
             $this->notFound = $func;
233 233
         }
234 234
     }
@@ -246,17 +246,17 @@  discard block
 block discarded – undo
246 246
     public function run() {
247 247
         $found = false;
248 248
         $counter = 0;
249
-        while($found === false && $counter < count($this->routes)) {
250
-            if($this->routerParser->match($this->routes[$counter]->getUri()) && $this->routes[$counter]->getMethod() === $this->requestMethod) {
249
+        while ($found === false && $counter < count($this->routes)) {
250
+            if ($this->routerParser->match($this->routes[$counter]->getUri()) && $this->routes[$counter]->getMethod() === $this->requestMethod) {
251 251
                 $found = true;
252 252
             } else {
253 253
                 $counter++;
254 254
             }
255 255
         }
256 256
 
257
-        if($found) {
257
+        if ($found) {
258 258
             // run the before middleware if it exists
259
-            if($this->routes[$counter]->hasBefore()) {
259
+            if ($this->routes[$counter]->hasBefore()) {
260 260
                 call_user_func($this->routes[$counter]->getMiddlewares()['before']);
261 261
             }
262 262
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
             $response = call_user_func_array($this->routes[$counter]->getResponse(), $params);
265 265
 
266 266
             // run the after middleware if it exists
267
-            if($this->routes[$counter]->hasAfter()) {
267
+            if ($this->routes[$counter]->hasAfter()) {
268 268
                 call_user_func($this->routes[$counter]->getMiddlewares()['after']);
269 269
             }
270 270
 
Please login to merge, or discard this patch.
Routify/Order.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 
45 45
     public function __construct($uri, $method, $response, array $middlewares = []) {
46 46
         $this->uri = $uri;
47
-        if(!in_array(mb_strtoupper($method), $this->availableRequestMethods)) {
47
+        if (!in_array(mb_strtoupper($method), $this->availableRequestMethods)) {
48 48
             throw new MethodException("The request method is invalid");
49 49
         }
50 50
         $this->method = $method;
51 51
         $this->response = $response;
52
-        if($this->isValidMiddleware($middlewares)) {
52
+        if ($this->isValidMiddleware($middlewares)) {
53 53
             $this->middlewares = $middlewares;
54 54
         }
55 55
     }
@@ -126,15 +126,15 @@  discard block
 block discarded – undo
126 126
 
127 127
     private function isValidMiddleware($middleware) {
128 128
         // if there is not middlewares then it is valid
129
-        if(count($middleware) === 0) {
129
+        if (count($middleware) === 0) {
130 130
             return true;
131 131
         }
132 132
 
133
-        foreach($middleware as $key => $value) {
134
-            if(!in_array($key, $this->middlewareTypes)) {
133
+        foreach ($middleware as $key => $value) {
134
+            if (!in_array($key, $this->middlewareTypes)) {
135 135
                 throw new InvalidMiddlewareException("Only before and after middleware types are valid");
136 136
             }
137
-            if(!is_callable($value)) {
137
+            if (!is_callable($value)) {
138 138
                 throw new InvalidMiddlewareException("The middleware must be callable");
139 139
             }
140 140
         }
Please login to merge, or discard this patch.