Completed
Push — master ( 809108...984872 )
by Marco
05:49
created
src/Comodojo/Dispatcher/Router/Route.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,8 +80,8 @@
 block discarded – undo
80 80
     protected $error_message;
81 81
 
82 82
     /**
83
-    * @var array
84
-    */
83
+     * @var array
84
+     */
85 85
     protected $parameters = [];
86 86
 
87 87
     /**
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -357,13 +357,13 @@  discard block
 block discarded – undo
357 357
     public function path($path) {
358 358
 
359 359
         // Because of the nature of the global regular expression, all the bits of the matched route are associated with a parameter key
360
-        foreach ($this->query as $key => $value) {
360
+        foreach ( $this->query as $key => $value ) {
361 361
 
362 362
             if ( isset($path[$key]) ) {
363 363
                 /* if it's available a bit associated with the parameter name, it is compared against
364 364
                  * it's regular expression in order to extrect backreferences
365 365
                  */
366
-                if ( preg_match('/^' . $value['regex'] . '$/', $path[$key], $matches) ) {
366
+                if ( preg_match('/^'.$value['regex'].'$/', $path[$key], $matches) ) {
367 367
 
368 368
                     if ( count($matches) == 1 ) $matches = $matches[0]; // This is the case where no backreferences are present or available.
369 369
 
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 
373 373
                 }
374 374
 
375
-            } elseif ($value['required']) {
375
+            } elseif ( $value['required'] ) {
376 376
 
377 377
                 throw new DispatcherException(sprintf("Required parameter '%s' not specified.", $key), 1, null, 500);
378 378
 
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
      */
392 392
     public function serialize() {
393 393
 
394
-        return serialize( (object) [
394
+        return serialize((object)[
395 395
             'classname' => $this->classname,
396 396
             'type' => $this->type,
397 397
             'service' => $this->service,
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Traits/HeadersTrait.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 
29 29
     public function get($header = null) {
30 30
 
31
-        if (is_null($header)) return $this->headers;
31
+        if ( is_null($header) ) return $this->headers;
32 32
 
33
-        else if (array_key_exists($header, $this->headers)) return $this->headers[$header];
33
+        else if ( array_key_exists($header, $this->headers) ) return $this->headers[$header];
34 34
 
35 35
         else return null;
36 36
 
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 
39 39
     public function getAsString($header = null) {
40 40
 
41
-        if (is_null($header)) {
41
+        if ( is_null($header) ) {
42 42
 
43 43
             return array_map([$this, 'headerToString'],
44 44
                 array_keys($this->headers),
45 45
                 array_values($this->headers)
46 46
             );
47 47
 
48
-        } else if (array_key_exists($header, $this->headers)) {
48
+        } else if ( array_key_exists($header, $this->headers) ) {
49 49
 
50 50
             return self::headerToString($header, $this->headers[$header]);
51 51
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 
58 58
     public function set($header, $value = null) {
59 59
 
60
-        if (is_null($value)) {
60
+        if ( is_null($value) ) {
61 61
 
62 62
             $header = explode(":", $header, 2);
63 63
 
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
 
76 76
     public function delete($header = null) {
77 77
 
78
-        if (is_null($header)) {
78
+        if ( is_null($header) ) {
79 79
 
80 80
             $this->headers = array();
81 81
 
82 82
             return true;
83 83
 
84
-        } else if (array_key_exists($header, $this->headers)) {
84
+        } else if ( array_key_exists($header, $this->headers) ) {
85 85
 
86 86
             unset($this->headers[$header]);
87 87
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 
98 98
     public function merge($headers) {
99 99
 
100
-        foreach ($headers as $key => $value) {
100
+        foreach ( $headers as $key => $value ) {
101 101
             $this->set($key, $value);
102 102
         }
103 103
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Router/Model.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 
108 108
     public function route(Request $request) {
109 109
 
110
-        $method = (string) $request->getMethod();
110
+        $method = (string)$request->getMethod();
111 111
 
112 112
         $methods = $this->configuration->get('allowed-http-methods');
113 113
 
114
-        if (!empty($methods) && in_array($method, $methods) === false) {
114
+        if ( !empty($methods) && in_array($method, $methods) === false ) {
115 115
 
116 116
             throw new DispatcherException("Method not allowed", 0, null, 405, array(
117 117
                 "Allow" => implode(",", $methods)
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 
122 122
         $this->setRequest($request);
123 123
 
124
-        if ($this->bypass_routing === false) {
124
+        if ( $this->bypass_routing === false ) {
125 125
 
126
-            if (!$this->parse()) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404);
126
+            if ( !$this->parse() ) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404);
127 127
 
128 128
         }
129 129
 
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
 
136 136
         $class = $this->route->getClassName();
137 137
 
138
-        if (class_exists($class)) {
138
+        if ( class_exists($class) ) {
139 139
 
140 140
             // All the route parameters are also added to the query parameters
141
-            foreach ($this->route->getRequestParameters() as $parameter => $value) {
141
+            foreach ( $this->route->getRequestParameters() as $parameter => $value ) {
142 142
                 $this->getRequest()->getQuery()->set($parameter, $value);
143 143
             }
144 144
 
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
 
164 164
         $this->setResponse($response);
165 165
 
166
-        if (is_null($this->route)) {
166
+        if ( is_null($this->route) ) {
167 167
 
168 168
             throw new DispatcherException("Route has not been loaded!");
169 169
 
170 170
         }
171 171
 
172
-        if ($this->bypass_service) {
172
+        if ( $this->bypass_service ) {
173 173
 
174 174
             return;
175 175
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 
178 178
         $service = $this->getServiceInstance();
179 179
 
180
-        if (!is_null($service)) {
180
+        if ( !is_null($service) ) {
181 181
 
182 182
             $result = "";
183 183
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 
186 186
             $methods = $service->getImplementedMethods();
187 187
 
188
-            if (in_array($method, $methods)) {
188
+            if ( in_array($method, $methods) ) {
189 189
 
190 190
                 $callable = $service->getMethod($method);
191 191
 
@@ -225,10 +225,10 @@  discard block
 block discarded – undo
225 225
 
226 226
         $path = urldecode($this->getRequest()->route());
227 227
 
228
-        foreach ($this->table->getRoutes() as $regex => $value) {
228
+        foreach ( $this->table->getRoutes() as $regex => $value ) {
229 229
 
230 230
             // The current uri is checked against all the global regular expressions associated with the routes
231
-            if (preg_match("/".$regex."/", $path, $matches)) {
231
+            if ( preg_match("/".$regex."/", $path, $matches) ) {
232 232
 
233 233
                 /* If a route is matched, all the bits of the route string are evalued in order to create
234 234
                  * new query parameters which will be available for the service class
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Router/Table.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      * Types of route that this table will accept
42 42
      * @var array
43 43
      */
44
-    const ALLOWED_ROUTES = [ "ROUTE", "REDIRECT", "ERROR" ];
44
+    const ALLOWED_ROUTES = ["ROUTE", "REDIRECT", "ERROR"];
45 45
 
46 46
     /**
47 47
      * Current repository of routes
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 
142 142
         $regex = $this->regex($route);
143 143
 
144
-        if (isset($this->routes[$regex])) {
144
+        if ( isset($this->routes[$regex]) ) {
145 145
             return $this->routes[$regex];
146 146
         }
147 147
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 
164 164
         $routes = $this->routes;
165 165
 
166
-        if (isset($routes[$regex])) {
166
+        if ( isset($routes[$regex]) ) {
167 167
 
168 168
             unset($routes[$regex]);
169 169
 
@@ -185,9 +185,9 @@  discard block
 block discarded – undo
185 185
 
186 186
     public function load(array $routes) {
187 187
 
188
-        if (!empty($routes)) {
188
+        if ( !empty($routes) ) {
189 189
 
190
-            foreach ($routes as $name => $route) {
190
+            foreach ( $routes as $name => $route ) {
191 191
 
192 192
                 $this->add(
193 193
                     $route['route'],
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
 
250 250
     private function readCache() {
251 251
 
252
-        if ($this->configuration->get('routing-table-cache') !== true) return;
252
+        if ( $this->configuration->get('routing-table-cache') !== true ) return;
253 253
 
254 254
         $data = $this->cache->read();
255 255
 
256
-        if (is_null($data)) {
256
+        if ( is_null($data) ) {
257 257
 
258 258
             $this->routes = [];
259 259
 
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 
270 270
     private function dumpCache() {
271 271
 
272
-        if ($this->configuration->get('routing-table-cache') !== true) return;
272
+        if ( $this->configuration->get('routing-table-cache') !== true ) return;
273 273
 
274 274
         $ttl = $this->configuration->get('routing-table-ttl');
275 275
 
276
-        if ($this->cache->dump($this->routes, $ttl)) {
276
+        if ( $this->cache->dump($this->routes, $ttl) ) {
277 277
             $this->logger->debug("Routing table saved to cache");
278 278
         } else {
279 279
             $this->logger->warning("Cannot save routing table to cache");
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Router/Parser.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
     // the global regular expression against which all the request URI will be compared
42 42
     public function read($folders = array(), Route $value = null, $regex = '') {
43 43
 
44
-        if (is_null($value)) {
44
+        if ( is_null($value) ) {
45 45
 
46 46
             $value = new Route();
47 47
 
48 48
         }
49 49
 
50 50
         // if the first 'folder' is empty is removed
51
-        while (!empty($folders) && empty($folders[0])) {
51
+        while ( !empty($folders) && empty($folders[0]) ) {
52 52
 
53 53
             array_shift($folders);
54 54
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 
57 57
         // if the 'folder' array is empty, the route has been fully analyzed
58 58
         // this is the exit condition from the recursive loop.
59
-        if (empty($folders)) {
59
+        if ( empty($folders) ) {
60 60
 
61 61
             return '^'.$regex.'[\/]?$';
62 62
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
             // All the parameters of the route must be json strings
69 69
             $decoded = json_decode($folder, true);
70 70
 
71
-            if (!is_null($decoded) && is_array($decoded)) {
71
+            if ( !is_null($decoded) && is_array($decoded) ) {
72 72
 
73 73
                 $param_regex = '';
74 74
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
                  *
85 85
                  * This is the reason of the following 'foreach'
86 86
                  */
87
-                foreach ($decoded as $key => $string) {
87
+                foreach ( $decoded as $key => $string ) {
88 88
 
89 89
                     $this->logger->debug("Route parser - parameter key: $key");
90 90
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
                      */
97 97
                     $param_regex .= $this->param($key, $string, $value);
98 98
 
99
-                    if ($value->isQueryRequired($key)) {
99
+                    if ( $value->isQueryRequired($key) ) {
100 100
                         $param_required = true;
101 101
                     }
102 102
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         $field_required = false;
133 133
 
134 134
         // If the field name ends with a '*', the parameter is considered as required
135
-        if (preg_match('/^(.+)\*$/', $key, $bits)) {
135
+        if ( preg_match('/^(.+)\*$/', $key, $bits) ) {
136 136
 
137 137
             $key = $bits[1];
138 138
             $field_required = true;
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Response/Content.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
 
44 44
     public function set($content = null) {
45 45
 
46
-        if (!is_scalar($content) && $content != null) {
46
+        if ( !is_scalar($content) && $content != null ) {
47 47
 
48 48
             throw new Exception("Invalid HTTP content");
49 49
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Response/Status.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
     public function set($code) {
50 50
 
51
-        if (!$this->codes->exists($code)) {
51
+        if ( !$this->codes->exists($code) ) {
52 52
 
53 53
             throw new Exception("Invalid HTTP Status Code $code");
54 54
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
     }
62 62
 
63
-    public function description($code=null) {
63
+    public function description($code = null) {
64 64
 
65 65
         if ( is_null($code) ) return $this->codes->getMessage($this->status_code);
66 66
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Response/Model.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
 
162 162
     public function import($data) {
163 163
 
164
-        if (isset($data->headers)) $this->setHeaders($data->headers);
165
-        if (isset($data->status)) $this->setStatus($data->status);
166
-        if (isset($data->content)) $this->setContent($data->content);
167
-        if (isset($data->location)) $this->setLocation($data->location);
164
+        if ( isset($data->headers) ) $this->setHeaders($data->headers);
165
+        if ( isset($data->status) ) $this->setStatus($data->status);
166
+        if ( isset($data->content) ) $this->setContent($data->content);
167
+        if ( isset($data->location) ) $this->setLocation($data->location);
168 168
 
169
-        if (isset($data->cookies) && is_array($data->cookies)) {
169
+        if ( isset($data->cookies) && is_array($data->cookies) ) {
170 170
             $cookies = $this->getCookies();
171
-            foreach ($data->cookies as $name => $cookie) $cookies->add($cookie);
171
+            foreach ( $data->cookies as $name => $cookie ) $cookies->add($cookie);
172 172
         }
173 173
 
174 174
     }
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         $output_class_name = "\\Comodojo\\Dispatcher\\Response\\Preprocessor\\Status".$status;
181 181
 
182 182
         // @TODO: this condition will be removed when all preprocessors ready
183
-        if (class_exists($output_class_name)) {
183
+        if ( class_exists($output_class_name) ) {
184 184
             $output = new $output_class_name($this);
185 185
         } else {
186 186
             $output = new \Comodojo\Dispatcher\Response\Preprocessor\Status200($this);
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
         $output->consolidate();
190 190
 
191
-        if ($route != null) {
191
+        if ( $route != null ) {
192 192
             $this->setClientCache($request, $route);
193 193
         }
194 194
 
@@ -196,19 +196,19 @@  discard block
 block discarded – undo
196 196
         $content = $this->getContent();
197 197
         $headers = $this->getHeaders();
198 198
 
199
-        if ((string)$request->getMethod() == 'HEAD' && !in_array($status, self::$no_content_statuses)) {
199
+        if ( (string)$request->getMethod() == 'HEAD' && !in_array($status, self::$no_content_statuses) ) {
200 200
             $length = $content->length();
201 201
             $content->set(null);
202
-            if ($length) {
202
+            if ( $length ) {
203 203
                 $headers->set('Content-Length', $length);
204 204
             }
205 205
         }
206 206
 
207
-        if ($headers->get('Transfer-Encoding') != null) {
207
+        if ( $headers->get('Transfer-Encoding') != null ) {
208 208
             $headers->delete('Content-Length');
209 209
         }
210 210
 
211
-        if ((string)$request->getVersion() == '1.0' && false !== strpos($headers->get('Cache-Control'), 'no-cache')) {
211
+        if ( (string)$request->getVersion() == '1.0' && false !== strpos($headers->get('Cache-Control'), 'no-cache') ) {
212 212
             $headers->set('pragma', 'no-cache');
213 213
             $headers->set('expires', -1);
214 214
         }
@@ -229,9 +229,9 @@  discard block
 block discarded – undo
229 229
         ) {
230 230
 
231 231
             $headers = $this->getHeaders();
232
-            $timestamp = (int) $this->getTime()->format('U')+$ttl;
232
+            $timestamp = (int)$this->getTime()->format('U')+$ttl;
233 233
 
234
-            if ($ttl > 0) {
234
+            if ( $ttl > 0 ) {
235 235
 
236 236
                 $headers->set("Cache-Control", "max-age=".$ttl.", must-revalidate");
237 237
                 $headers->set("Expires", gmdate("D, d M Y H:i:s", $timestamp)." GMT");
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Response/Preprocessor/Status301.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@
 block discarded – undo
32 32
 
33 33
         $location = $this->response->getLocation()->get();
34 34
 
35
-        if (empty($location)) throw new Exception("Invalid location, cannot redirect");
35
+        if ( empty($location) ) throw new Exception("Invalid location, cannot redirect");
36 36
 
37 37
         $this->response->getHeaders()->set("Location", $location);
38 38
 
39 39
         $content = $this->response->getContent();
40 40
 
41
-        if (empty($content->get())) {
41
+        if ( empty($content->get()) ) {
42 42
 
43 43
             $content->set(sprintf('<!DOCTYPE html>
44 44
 <html>
Please login to merge, or discard this patch.