Completed
Push — master ( ca8209...ce9662 )
by Marco
12:13
created
src/Cache.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
      * Constructor method. It only acquire current time and notify that cache is ready
60 60
      *
61 61
      * @param   float   $time   Dispatcher time
62
-     * @param   Object  $logger Logger, injected by dispatcher
62
+     * @param   Debug  $logger Logger, injected by dispatcher
63 63
      */
64 64
     final public function __construct($time, $logger) {
65 65
 
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -189,7 +189,7 @@
 block discarded – undo
189 189
                 "bestbefore"=>  $best_before,
190 190
                 //"content" =>  $u_data["cache_content"]
191 191
                 "object"    =>  $u_data
192
-             );
192
+                );
193 193
 
194 194
         }
195 195
         
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
             }
106 106
         }
107 107
         
108
-        $cacheTag = md5($request) . ".cache";
108
+        $cacheTag = md5($request).".cache";
109 109
 
110
-        $cacheFile = $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cacheTag;
110
+        $cacheFile = $this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cacheTag;
111 111
 
112 112
         $f_data = serialize($data);
113 113
 
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * 
139 139
      * @return  array   An array containing maxage, bestbefore, object (data)
140 140
      */
141
-    final public function get($request, $ttl=DISPATCHER_CACHE_TTL) {
141
+    final public function get($request, $ttl = DISPATCHER_CACHE_TTL) {
142 142
         
143 143
         if (!DISPATCHER_CACHE_ENABLED) {
144 144
 
@@ -148,19 +148,19 @@  discard block
 block discarded – undo
148 148
 
149 149
         }
150 150
         
151
-        $last_time_limit = (int)$this->current_time - $ttl;
151
+        $last_time_limit = (int)$this->current_time-$ttl;
152 152
         
153
-        $cacheTag = md5($request) . ".cache";
153
+        $cacheTag = md5($request).".cache";
154 154
 
155
-        $cacheFile = $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cacheTag;
155
+        $cacheFile = $this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cacheTag;
156 156
         
157 157
         $cache_time = @filemtime($cacheFile);
158 158
 
159 159
         if (is_readable($cacheFile) AND $cache_time >= $last_time_limit) {
160 160
             
161
-            $max_age = $cache_time + $ttl - (int)$this->current_time;
161
+            $max_age = $cache_time+$ttl-(int)$this->current_time;
162 162
 
163
-            $best_before = gmdate("D, d M Y H:i:s", $cache_time + $ttl) . " GMT";
163
+            $best_before = gmdate("D, d M Y H:i:s", $cache_time+$ttl)." GMT";
164 164
             
165 165
             $data = file_get_contents($cacheFile);
166 166
 
@@ -204,16 +204,16 @@  discard block
 block discarded – undo
204 204
      *
205 205
      * @return  bool
206 206
      */
207
-    public function purge($request=null) {
207
+    public function purge($request = null) {
208 208
 
209
-        if ( is_null($request) ) {
209
+        if (is_null($request)) {
210 210
 
211 211
             $this->logger->info('Purging whole cache');
212 212
 
213 213
             $cache_files_number = 0;
214 214
 
215 215
             $cache_path = opendir($this->cache_path);
216
-            if ( $cache_path === false ) {
216
+            if ($cache_path === false) {
217 217
 
218 218
                 $this->logger->error('Unable to open cache folder', array(
219 219
                     'CACHEFOLDER' => $this->cache_path
@@ -223,10 +223,10 @@  discard block
 block discarded – undo
223 223
 
224 224
             }
225 225
             
226
-            while( false !== ( $cache_file = readdir($cache_path) ) ) {
226
+            while (false !== ($cache_file = readdir($cache_path))) {
227 227
 
228
-                if ( pathinfo($cache_file, PATHINFO_EXTENSION) == "cache" ) {
229
-                    if ( unlink( $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cache_file ) == false ) return false;
228
+                if (pathinfo($cache_file, PATHINFO_EXTENSION) == "cache") {
229
+                    if (unlink($this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cache_file) == false) return false;
230 230
                     else $cache_files_number++;
231 231
                 }
232 232
                 else continue;
@@ -242,11 +242,11 @@  discard block
 block discarded – undo
242 242
                 'REQUEST' => $request
243 243
             ));
244 244
 
245
-            $cacheTag = md5($request) . ".cache";
245
+            $cacheTag = md5($request).".cache";
246 246
 
247
-            $cacheFile = $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cacheTag;
247
+            $cacheFile = $this->cache_path.($this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/").$cacheTag;
248 248
 
249
-            if ( is_readable($cacheFile) ) {
249
+            if (is_readable($cacheFile)) {
250 250
 
251 251
                 $unlink = unlink($cacheFile);
252 252
                 $cache_files_number = $unlink ? 1 : false;
Please login to merge, or discard this patch.
Braces   +15 added lines, -14 removed lines patch added patch discarded remove patch
@@ -95,8 +95,7 @@  discard block
 block discarded – undo
95 95
 
96 96
                 return false;
97 97
 
98
-            }
99
-            else {
98
+            } else {
100 99
 
101 100
                 $this->logger->error('Empty data, nothign to cache');
102 101
 
@@ -120,8 +119,7 @@  discard block
 block discarded – undo
120 119
             
121 120
             if ($this->fail_silently) {
122 121
                 return false;
123
-            }
124
-            else {
122
+            } else {
125 123
                 throw new IOException("Error writing to cache");
126 124
             }
127 125
         }
@@ -176,8 +174,7 @@  discard block
 block discarded – undo
176 174
 
177 175
                     return false;
178 176
 
179
-                }
180
-                else {
177
+                } else {
181 178
 
182 179
                     throw new IOException("Error reading from cache");
183 180
 
@@ -191,10 +188,10 @@  discard block
 block discarded – undo
191 188
                 "object"    =>  $u_data
192 189
              );
193 190
 
191
+        } else {
192
+            return false;
194 193
         }
195 194
         
196
-        else return false;
197
-        
198 195
     }
199 196
 
200 197
     /**
@@ -226,17 +223,20 @@  discard block
 block discarded – undo
226 223
             while( false !== ( $cache_file = readdir($cache_path) ) ) {
227 224
 
228 225
                 if ( pathinfo($cache_file, PATHINFO_EXTENSION) == "cache" ) {
229
-                    if ( unlink( $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cache_file ) == false ) return false;
230
-                    else $cache_files_number++;
226
+                    if ( unlink( $this->cache_path . ( $this->cache_path[strlen($this->cache_path)-1] == "/" ? "" : "/" ) . $cache_file ) == false ) {
227
+                        return false;
228
+                    } else {
229
+                        $cache_files_number++;
230
+                    }
231
+                } else {
232
+                    continue;
231 233
                 }
232
-                else continue;
233 234
                 
234 235
             }
235 236
           
236 237
             closedir($cache_path);
237 238
 
238
-        }
239
-        else {
239
+        } else {
240 240
 
241 241
             $this->logger->info('Purging request cache', array(
242 242
                 'REQUEST' => $request
@@ -251,8 +251,9 @@  discard block
 block discarded – undo
251 251
                 $unlink = unlink($cacheFile);
252 252
                 $cache_files_number = $unlink ? 1 : false;
253 253
 
254
+            } else {
255
+                $cache_files_number = 0;
254 256
             }
255
-            else $cache_files_number = 0;
256 257
 
257 258
         }
258 259
 
Please login to merge, or discard this patch.
src/Dispatcher.php 3 patches
Doc Comments   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
     /**
693 693
      * Return dispatcher baseurl, no matter the request
694 694
      *
695
-     * @return uri  The baseurl
695
+     * @return string  The baseurl
696 696
      */
697 697
     private function urlGetAbsolute($service=null) {
698 698
 
@@ -841,6 +841,9 @@  discard block
 block discarded – undo
841 841
 
842 842
     }
843 843
 
844
+    /**
845
+     * @return ObjectResultInterface
846
+     */
844 847
     private function runService(ObjectRequest $request, ObjectRoute $route) {
845 848
 
846 849
         $method = $request->getMethod();
@@ -973,7 +976,7 @@  discard block
 block discarded – undo
973 976
     /**
974 977
      * Route request handling ObjectResult hooks
975 978
      *
976
-     * @param   ObjectResult    $route  An implementation of ObjectResultInterface
979
+     * @param   ObjectResultInterface    $route  An implementation of ObjectResultInterface
977 980
      * @return  string                  Content (stuff that will go on screen)
978 981
      */
979 982
     private function route(ObjectResultInterface $route) {
@@ -1068,6 +1071,9 @@  discard block
 block discarded – undo
1068 1071
 
1069 1072
     }
1070 1073
 
1074
+    /**
1075
+     * @param string $result
1076
+     */
1071 1077
     private static function end($result) {
1072 1078
 
1073 1079
         if ( defined('DISPATCHER_PHPUNIT_TEST') && @constant('DISPATCHER_PHPUNIT_TEST') === true ) {
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 
182 182
         // Starts composing request object (ObjectRequest)
183 183
 
184
-        list($request_service,$request_attributes) = $this->urlInterpreter($this->working_mode);
184
+        list($request_service, $request_attributes) = $this->urlInterpreter($this->working_mode);
185 185
 
186 186
         list($request_parameters, $request_raw_parameters) = $this->deserializeParameters($this->request_method);
187 187
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 
190 190
         // Before composing the object request, remember to define the current (absolute) dispatcher baseurl
191 191
         // (if not specified in dispatcher-config)
192
-        if ( !defined("DISPATCHER_BASEURL") ) define("DISPATCHER_BASEURL",$this->urlGetAbsolute($request_service));
192
+        if (!defined("DISPATCHER_BASEURL")) define("DISPATCHER_BASEURL", $this->urlGetAbsolute($request_service));
193 193
 
194 194
         // Now let's compose request object
195 195
 
@@ -218,21 +218,21 @@  discard block
 block discarded – undo
218 218
      * @param   array   $parameters (optional) Service options (cache, ...)
219 219
      * @param   bool    $relative   (optional) If true, target will be assumed in default service directory
220 220
      */
221
-    final public function setRoute($service, $type, $target, $parameters=Array(), $relative=true) {
221
+    final public function setRoute($service, $type, $target, $parameters = Array(), $relative = true) {
222 222
 
223 223
         try {
224 224
 
225
-            if ( strtoupper($type) == "ROUTE" ) {
225
+            if (strtoupper($type) == "ROUTE") {
226 226
 
227
-                if ( $relative ) $this->routingtable->setRoute($service, $type, DISPATCHER_SERVICES_FOLDER.$target, $parameters);
227
+                if ($relative) $this->routingtable->setRoute($service, $type, DISPATCHER_SERVICES_FOLDER.$target, $parameters);
228 228
 
229 229
                 else $this->routingtable->setRoute($service, $type, $target, $parameters);
230 230
 
231 231
             }
232 232
 
233
-            else if ( strtoupper($type) == "REDIRECT" ) {
233
+            else if (strtoupper($type) == "REDIRECT") {
234 234
 
235
-                if ( $relative ) $this->routingtable->setRoute($service, $type, DISPATCHER_BASEURL.$target, $parameters);
235
+                if ($relative) $this->routingtable->setRoute($service, $type, DISPATCHER_BASEURL.$target, $parameters);
236 236
 
237 237
                 else $this->routingtable->setRoute($service, $type, $target, $parameters);
238 238
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
         } catch (Exception $e) {
244 244
 
245 245
             //debug error but do not stop dispatcher
246
-            $this->logger->warning( 'Unable to set route'.Array('SERVIVE' => $service) );
246
+            $this->logger->warning('Unable to set route'.Array('SERVIVE' => $service));
247 247
 
248 248
         }
249 249
 
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
         } catch (Exception $e) {
266 266
 
267 267
             //debug error but do not stop dispatcher
268
-            $this->logger->warning( 'Unable to unset route'.Array('SERVIVE' => $service) );
268
+            $this->logger->warning('Unable to unset route'.Array('SERVIVE' => $service));
269 269
 
270 270
         }
271 271
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * @param   string  $callback   The callback (or class if $method is specified)
279 279
      * @param   string  $method     (optional) Method for $callback
280 280
      */
281
-    final public function addHook($event, $callback, $method=null) {
281
+    final public function addHook($event, $callback, $method = null) {
282 282
 
283 283
         try {
284 284
 
@@ -287,11 +287,11 @@  discard block
 block discarded – undo
287 287
         } catch (Exception $e) {
288 288
 
289 289
             //debug error but do not stop dispatcher
290
-            $this->logger->warning( 'Unable to add hook'.Array(
290
+            $this->logger->warning('Unable to add hook'.Array(
291 291
                 'CALLBACK' => $callback,
292 292
                 'METHOD' => $method,
293 293
                 'EVENT' => $event
294
-            ) );
294
+            ));
295 295
 
296 296
         }
297 297
 
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      * @param   string  $event      The event name
304 304
      * @param   string  $callback   The callback (or class if $method is specified)
305 305
      */
306
-    final public function removeHook($event, $callback=null) {
306
+    final public function removeHook($event, $callback = null) {
307 307
 
308 308
         try {
309 309
 
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
         } catch (Exception $e) {
313 313
 
314 314
             //debug error but do not stop dispatcher
315
-            $this->logger->warning( 'Unable to remove hook'.Array(
315
+            $this->logger->warning('Unable to remove hook'.Array(
316 316
                 'CALLBACK' => $callback,
317 317
                 'EVENT' => $event
318
-            ) );
318
+            ));
319 319
 
320 320
         }
321 321
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
      * @param   string  $plugin     The plugin name
328 328
      * @param   string  $folder     (optional) plugin folder (if omitted, dispatcher will use default one)
329 329
      */
330
-    final public function loadPlugin($plugin, $folder=DISPATCHER_PLUGINS_FOLDER) {
330
+    final public function loadPlugin($plugin, $folder = DISPATCHER_PLUGINS_FOLDER) {
331 331
 
332 332
         include $folder.$plugin.".php";
333 333
 
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
      */
365 365
     final public function clearCache($all = null) {
366 366
 
367
-        return $this->cacher->purge( $all == true ? null : $this->service_url );
367
+        return $this->cacher->purge($all == true ? null : $this->service_url);
368 368
 
369 369
     }
370 370
 
@@ -380,26 +380,26 @@  discard block
 block discarded – undo
380 380
 
381 381
         $fork = $this->events->fire("dispatcher", "DISPATCHER", $this->enabled);
382 382
 
383
-        if ( is_bool($fork)  ) $this->enabled = $fork;
383
+        if (is_bool($fork)) $this->enabled = $fork;
384 384
 
385 385
         // After building dispatcher instance, fire THE level2 event "dispatcher.request"
386 386
         // This default hook will expose current request (ObjectRequest) to callbacks
387 387
 
388 388
         $fork = $this->events->fire("dispatcher.request", "REQUEST", $this->request);
389 389
 
390
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork;
390
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest) $this->request = $fork;
391 391
 
392 392
         // Fire level3 event "dispatcher.request.[method]"
393 393
         
394 394
         $fork = $this->events->fire("dispatcher.request.".$this->request_method, "REQUEST", $this->request);
395 395
 
396
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork;
396
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest) $this->request = $fork;
397 397
 
398 398
         // Fire level3 event "dispatcher.request.[service]"
399 399
         
400 400
         $fork = $this->events->fire("dispatcher.request.".$this->request->getService(), "REQUEST", $this->request);
401 401
 
402
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork;
402
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest) $this->request = $fork;
403 403
 
404 404
         // Fire special event, it will not modify request
405 405
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 
408 408
         // Check if dispatcher is enabled
409 409
 
410
-        if ( $this->enabled == false ) {
410
+        if ($this->enabled == false) {
411 411
 
412 412
             $route = new ObjectError();
413 413
             $route->setStatusCode(503);
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 
427 427
         $fork = $this->events->fire("dispatcher.routingtable", "TABLE", $this->routingtable);
428 428
 
429
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable ) $this->routingtable = $fork;
429
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable) $this->routingtable = $fork;
430 430
 
431 431
         // Retrieve current route from routing table
432 432
 
@@ -443,34 +443,34 @@  discard block
 block discarded – undo
443 443
             ->setType($preroute["type"])
444 444
             ->setTarget($preroute["target"]);
445 445
 
446
-        if ( isset($preroute["parameters"]["class"]) ) {
446
+        if (isset($preroute["parameters"]["class"])) {
447 447
             $this->serviceroute->setClass($preroute["parameters"]["class"]);
448 448
         } else {
449 449
             $t = pathinfo($preroute["target"]);
450 450
             $this->serviceroute->setClass(preg_replace('/\\.[^.\\s]{3,4}$/', '', $t["filename"]));
451 451
         }
452 452
         
453
-        if ( isset($preroute["parameters"]["redirectCode"]) ) {
453
+        if (isset($preroute["parameters"]["redirectCode"])) {
454 454
             $this->serviceroute->setRedirectCode($preroute["parameters"]["redirectCode"]);
455 455
             unset($preroute["parameters"]["redirectCode"]);
456 456
         }
457
-        if ( isset($preroute["parameters"]["errorCode"]) ) {
457
+        if (isset($preroute["parameters"]["errorCode"])) {
458 458
             $this->serviceroute->setErrorCode($preroute["parameters"]["errorCode"]);
459 459
             unset($preroute["parameters"]["errorCode"]);
460 460
         }
461
-        if ( isset($preroute["parameters"]["cache"]) ) {
461
+        if (isset($preroute["parameters"]["cache"])) {
462 462
             $this->serviceroute->setCache($preroute["parameters"]["cache"]);
463 463
             unset($preroute["parameters"]["cache"]);
464 464
         }
465
-        if ( isset($preroute["parameters"]["ttl"]) ) {
465
+        if (isset($preroute["parameters"]["ttl"])) {
466 466
             $this->serviceroute->setTtl($preroute["parameters"]["ttl"]);
467 467
             unset($preroute["parameters"]["ttl"]);
468 468
         }
469
-        if ( isset($preroute["parameters"]["headers"]) ) {
470
-            if ( is_array($preroute["parameters"]["headers"]) ) foreach ($preroute["parameters"]["headers"] as $header => $value) $this->serviceroute->setHeader($header, $value);
469
+        if (isset($preroute["parameters"]["headers"])) {
470
+            if (is_array($preroute["parameters"]["headers"])) foreach ($preroute["parameters"]["headers"] as $header => $value) $this->serviceroute->setHeader($header, $value);
471 471
             unset($preroute["parameters"]["headers"]);
472 472
         }
473
-        if ( isset($preroute["parameters"]["accessControl"]) ) {
473
+        if (isset($preroute["parameters"]["accessControl"])) {
474 474
             $this->serviceroute->setRedirectCode($preroute["parameters"]["accessControl"]);
475 475
             unset($preroute["parameters"]["accessControl"]);
476 476
         }
@@ -486,15 +486,15 @@  discard block
 block discarded – undo
486 486
 
487 487
         $fork = $this->events->fire("dispatcher.serviceroute", "ROUTE", $this->serviceroute);
488 488
 
489
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork;
489
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute) $this->serviceroute = $fork;
490 490
 
491 491
         $fork = $this->events->fire("dispatcher.serviceroute.".$this->serviceroute->getType(), "ROUTE", $this->serviceroute);
492 492
 
493
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork;
493
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute) $this->serviceroute = $fork;
494 494
 
495 495
         $fork = $this->events->fire("dispatcher.serviceroute.".$this->serviceroute->getService(), "ROUTE", $this->serviceroute);
496 496
 
497
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork;
497
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute) $this->serviceroute = $fork;
498 498
 
499 499
         // Fire special event, it will not modify route
500 500
 
@@ -504,11 +504,11 @@  discard block
 block discarded – undo
504 504
 
505 505
         $accesscontrol = preg_replace('/\s+/', '', $this->serviceroute->getAccessControl());
506 506
 
507
-        if ( $accesscontrol != null AND $accesscontrol != "*" ) {
507
+        if ($accesscontrol != null AND $accesscontrol != "*") {
508 508
 
509 509
             $origins = explode(",", $accesscontrol);
510 510
 
511
-            if ( !in_array(@$_SERVER['HTTP_ORIGIN'], $origins) ) {
511
+            if (!in_array(@$_SERVER['HTTP_ORIGIN'], $origins)) {
512 512
 
513 513
                 $route = new ObjectError();
514 514
                 $route->setStatusCode(403)->setContent("Origin not allowed");
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
             'REDIRECTCODE'  => $this->serviceroute->getRedirectCode()
536 536
         ));
537 537
 
538
-        switch($this->serviceroute->getType()) {
538
+        switch ($this->serviceroute->getType()) {
539 539
 
540 540
             case "ERROR":
541 541
 
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
             $uri = explode('/', $_SERVER['REQUEST_URI']);
621 621
             $scr = explode('/', $_SERVER['SCRIPT_NAME']);
622 622
 
623
-            for($i= 0;$i < sizeof($scr);$i++) {
623
+            for ($i = 0; $i < sizeof($scr); $i++) {
624 624
                 if ($uri[$i] == $scr[$i]) unset($uri[$i]);
625 625
             }
626 626
 
@@ -694,21 +694,21 @@  discard block
 block discarded – undo
694 694
      *
695 695
      * @return uri  The baseurl
696 696
      */
697
-    private function urlGetAbsolute($service=null) {
697
+    private function urlGetAbsolute($service = null) {
698 698
 
699
-        $http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://';
699
+        $http = 'http'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://';
700 700
 
701
-        if ( is_null($service) ) $uri = "";
701
+        if (is_null($service)) $uri = "";
702 702
 
703 703
         else {
704 704
 
705 705
             $self = $_SERVER['PHP_SELF'];
706 706
 
707
-            $uri = preg_replace("/\/index.php(.*?)$/i","",$self);
707
+            $uri = preg_replace("/\/index.php(.*?)$/i", "", $self);
708 708
 
709 709
         }
710 710
 
711
-        return ( $http . $_SERVER['HTTP_HOST'] . $uri . "/" );
711
+        return ($http.$_SERVER['HTTP_HOST'].$uri."/");
712 712
 
713 713
     }
714 714
 
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
 
733 733
         $parameters = Array();
734 734
 
735
-        switch($method) {
735
+        switch ($method) {
736 736
 
737 737
             case 'POST':
738 738
 
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 
756 756
     private function attributesMatch($provided, $expected, $liked) {
757 757
 
758
-        if ( $this->working_mode == "STANDARD" ) return $this->parametersMatch($provided, $expected, $liked);
758
+        if ($this->working_mode == "STANDARD") return $this->parametersMatch($provided, $expected, $liked);
759 759
 
760 760
         $attributes = Array();
761 761
 
@@ -763,9 +763,9 @@  discard block
 block discarded – undo
763 763
         $esize = sizeof($expected);
764 764
         $lsize = sizeof($liked);
765 765
 
766
-        if ( $psize < $esize ) throw new DispatcherException("Conversation error", 400);
766
+        if ($psize < $esize) throw new DispatcherException("Conversation error", 400);
767 767
 
768
-        else if ( $psize == $esize ) {
768
+        else if ($psize == $esize) {
769 769
 
770 770
             $attributes = $psize == 0 ? array() : array_combine($expected, $provided);
771 771
 
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 
774 774
         else {
775 775
 
776
-            if ( $esize == 0 ) {
776
+            if ($esize == 0) {
777 777
 
778 778
                 $e_attributes = array();
779 779
 
@@ -793,19 +793,19 @@  discard block
 block discarded – undo
793 793
 
794 794
             $l_attributes = Array();
795 795
 
796
-            if ( $lvaluessize < $lsize ) {
796
+            if ($lvaluessize < $lsize) {
797 797
 
798 798
                 $l_attributes = array_combine(array_slice($liked, 0, $lvaluessize), $lvalues);
799 799
 
800 800
             }
801
-            else if ( $lvaluessize == $lsize ) {
801
+            else if ($lvaluessize == $lsize) {
802 802
 
803 803
                 $l_attributes = $lvaluessize == 0 ? array() : array_combine($liked, $lvalues);
804 804
 
805 805
             }
806 806
             else {
807 807
 
808
-                if ( $lsize == 0 ) {
808
+                if ($lsize == 0) {
809 809
 
810 810
                     $l_attributes = $lvalues;
811 811
 
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 
834 834
         foreach ($expected as $parameter) {
835 835
 
836
-            if ( !isset($provided[$parameter]) ) throw new DispatcherException("Conversation error", 400);
836
+            if (!isset($provided[$parameter])) throw new DispatcherException("Conversation error", 400);
837 837
 
838 838
         }
839 839
 
@@ -851,11 +851,11 @@  discard block
 block discarded – undo
851 851
 
852 852
         // First of all, check cache (in case of GET request)
853 853
 
854
-        if ( $method == "GET" AND ( $cache == "SERVER" OR $cache == "BOTH" ) ) {
854
+        if ($method == "GET" AND ($cache == "SERVER" OR $cache == "BOTH")) {
855 855
 
856 856
             $from_cache = $this->cacher->get($this->service_url, $ttl);
857 857
 
858
-            if ( is_array($from_cache) ) {
858
+            if (is_array($from_cache)) {
859 859
 
860 860
                 $maxage = $from_cache["maxage"];
861 861
                 $bestbefore = $from_cache["bestbefore"];
@@ -873,13 +873,13 @@  discard block
 block discarded – undo
873 873
 
874 874
         // If there's no cache for this request, use routing information to find service
875 875
 
876
-        if ( (include($target)) === false ) throw new DispatcherException("Cannot run service", 500);
876
+        if ((include($target)) === false) throw new DispatcherException("Cannot run service", 500);
877 877
 
878 878
         // Find a service implementation and try to init it
879 879
 
880 880
         $service_class = $route->getClass();
881 881
 
882
-        if ( empty($service_class) ) throw new DispatcherException("Cannot run service", 500);
882
+        if (empty($service_class)) throw new DispatcherException("Cannot run service", 500);
883 883
 
884 884
         $service_class = "\\Comodojo\\Dispatcher\\Service\\".$service_class;
885 885
 
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 
900 900
         // Check if service supports current HTTP method
901 901
 
902
-        if ( !in_array($method, explode(",", $theservice->getSupportedMethods())) ) {
902
+        if (!in_array($method, explode(",", $theservice->getSupportedMethods()))) {
903 903
 
904 904
             throw new DispatcherException("Allow: ".$theservice->getSupportedMethods(), 405);
905 905
 
@@ -907,9 +907,9 @@  discard block
 block discarded – undo
907 907
 
908 908
         // Check if service implements current HTTP method
909 909
 
910
-        if ( !in_array($method, $theservice->getImplementedMethods()) ) {
910
+        if (!in_array($method, $theservice->getImplementedMethods())) {
911 911
 
912
-            throw new DispatcherException("Allow: ".implode(",",$theservice->getImplementedMethods()), 501);
912
+            throw new DispatcherException("Allow: ".implode(",", $theservice->getImplementedMethods()), 501);
913 913
 
914 914
         }
915 915
 
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
             $return->setService($service)
953 953
                 ->setStatusCode($theservice->getStatusCode())
954 954
                 ->setContent($result)
955
-                ->setHeaders( array_merge($theservice->getHeaders(), $route->getHeaders()) )
955
+                ->setHeaders(array_merge($theservice->getHeaders(), $route->getHeaders()))
956 956
                 ->setContentType($theservice->getContentType())
957 957
                 ->setCharset($theservice->getCharset());
958 958
             
@@ -982,15 +982,15 @@  discard block
 block discarded – undo
982 982
         // This means event engine will fire a dispatcher.[routetype] event
983 983
         // In case of wrong instance, create an ObjectError (500, null) instance
984 984
 
985
-        if ( $route instanceof ObjectSuccess ) {
985
+        if ($route instanceof ObjectSuccess) {
986 986
 
987 987
             $hook = "dispatcher.route";
988 988
 
989
-        } else if ( $route instanceof ObjectError ) {
989
+        } else if ($route instanceof ObjectError) {
990 990
 
991 991
             $hook = "dispatcher.error";
992 992
 
993
-        } else if ( $route instanceof ObjectRedirect ) {
993
+        } else if ($route instanceof ObjectRedirect) {
994 994
 
995 995
             $hook = "dispatcher.redirect";
996 996
 
@@ -1006,13 +1006,13 @@  discard block
 block discarded – undo
1006 1006
 
1007 1007
         $fork = $this->events->fire("dispatcher.result", "RESULT", $route);
1008 1008
 
1009
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork;
1009
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface) $route = $fork;
1010 1010
 
1011 1011
         // Fire second hook (level2), as specified above
1012 1012
 
1013 1013
         $fork = $this->events->fire($hook, "RESULT", $route);
1014 1014
 
1015
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork;
1015
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface) $route = $fork;
1016 1016
 
1017 1017
         // Now select and fire last hook (level3)
1018 1018
         // This means that event engine will fire something like "dispatcher.route.200"
@@ -1020,13 +1020,13 @@  discard block
 block discarded – undo
1020 1020
 
1021 1021
         $fork = $this->events->fire($hook.".".$route->getStatusCode(), "RESULT", $route);
1022 1022
 
1023
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork;
1023
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface) $route = $fork;
1024 1024
 
1025 1025
         // Fire special event, it may modify result
1026 1026
 
1027 1027
         $fork = $this->events->fire("dispatcher.result.#", "RESULT", $route);
1028 1028
 
1029
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork;
1029
+        if ($fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface) $route = $fork;
1030 1030
 
1031 1031
         // After hooks:
1032 1032
         // - store cache
@@ -1035,10 +1035,10 @@  discard block
 block discarded – undo
1035 1035
 
1036 1036
         $cache = $route instanceof \Comodojo\Dispatcher\ObjectResult\ObjectSuccess ? $this->serviceroute->getCache() : null;
1037 1037
 
1038
-        if ( $this->request_method == "GET" AND 
1039
-            ( $cache == "SERVER" OR $cache == "BOTH" ) AND
1038
+        if ($this->request_method == "GET" AND 
1039
+            ($cache == "SERVER" OR $cache == "BOTH") AND
1040 1040
             $this->result_comes_from_cache == false AND 
1041
-            $route instanceof \Comodojo\Dispatcher\ObjectResult\ObjectSuccess )
1041
+            $route instanceof \Comodojo\Dispatcher\ObjectResult\ObjectSuccess)
1042 1042
         {
1043 1043
 
1044 1044
             $this->cacher->set($this->service_url, $route);
@@ -1048,7 +1048,7 @@  discard block
 block discarded – undo
1048 1048
 
1049 1049
         $this->header->free();
1050 1050
 
1051
-        if ( $cache == "CLIENT" OR $cache == "BOTH" ) $this->header->setClientCache($this->serviceroute->getTtl());
1051
+        if ($cache == "CLIENT" OR $cache == "BOTH") $this->header->setClientCache($this->serviceroute->getTtl());
1052 1052
 
1053 1053
         $this->header->setContentType($route->getContentType(), $route->getCharset());
1054 1054
 
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
 
1071 1071
     private static function end($result) {
1072 1072
 
1073
-        if ( defined('DISPATCHER_PHPUNIT_TEST') && @constant('DISPATCHER_PHPUNIT_TEST') === true ) {
1073
+        if (defined('DISPATCHER_PHPUNIT_TEST') && @constant('DISPATCHER_PHPUNIT_TEST') === true) {
1074 1074
 
1075 1075
             return $result;
1076 1076
 
Please login to merge, or discard this patch.
Braces   +85 added lines, -50 removed lines patch added patch discarded remove patch
@@ -189,7 +189,9 @@  discard block
 block discarded – undo
189 189
 
190 190
         // Before composing the object request, remember to define the current (absolute) dispatcher baseurl
191 191
         // (if not specified in dispatcher-config)
192
-        if ( !defined("DISPATCHER_BASEURL") ) define("DISPATCHER_BASEURL",$this->urlGetAbsolute($request_service));
192
+        if ( !defined("DISPATCHER_BASEURL") ) {
193
+            define("DISPATCHER_BASEURL",$this->urlGetAbsolute($request_service));
194
+        }
193 195
 
194 196
         // Now let's compose request object
195 197
 
@@ -224,22 +226,24 @@  discard block
 block discarded – undo
224 226
 
225 227
             if ( strtoupper($type) == "ROUTE" ) {
226 228
 
227
-                if ( $relative ) $this->routingtable->setRoute($service, $type, DISPATCHER_SERVICES_FOLDER.$target, $parameters);
228
-
229
-                else $this->routingtable->setRoute($service, $type, $target, $parameters);
230
-
231
-            }
232
-
233
-            else if ( strtoupper($type) == "REDIRECT" ) {
229
+                if ( $relative ) {
230
+                    $this->routingtable->setRoute($service, $type, DISPATCHER_SERVICES_FOLDER.$target, $parameters);
231
+                } else {
232
+                    $this->routingtable->setRoute($service, $type, $target, $parameters);
233
+                }
234 234
 
235
-                if ( $relative ) $this->routingtable->setRoute($service, $type, DISPATCHER_BASEURL.$target, $parameters);
235
+            } else if ( strtoupper($type) == "REDIRECT" ) {
236 236
 
237
-                else $this->routingtable->setRoute($service, $type, $target, $parameters);
237
+                if ( $relative ) {
238
+                    $this->routingtable->setRoute($service, $type, DISPATCHER_BASEURL.$target, $parameters);
239
+                } else {
240
+                    $this->routingtable->setRoute($service, $type, $target, $parameters);
241
+                }
238 242
 
243
+            } else {
244
+                $this->routingtable->setRoute($service, $type, $target, $parameters);
239 245
             }
240 246
 
241
-            else $this->routingtable->setRoute($service, $type, $target, $parameters);
242
-
243 247
         } catch (Exception $e) {
244 248
 
245 249
             //debug error but do not stop dispatcher
@@ -380,26 +384,34 @@  discard block
 block discarded – undo
380 384
 
381 385
         $fork = $this->events->fire("dispatcher", "DISPATCHER", $this->enabled);
382 386
 
383
-        if ( is_bool($fork)  ) $this->enabled = $fork;
387
+        if ( is_bool($fork)  ) {
388
+            $this->enabled = $fork;
389
+        }
384 390
 
385 391
         // After building dispatcher instance, fire THE level2 event "dispatcher.request"
386 392
         // This default hook will expose current request (ObjectRequest) to callbacks
387 393
 
388 394
         $fork = $this->events->fire("dispatcher.request", "REQUEST", $this->request);
389 395
 
390
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork;
396
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) {
397
+            $this->request = $fork;
398
+        }
391 399
 
392 400
         // Fire level3 event "dispatcher.request.[method]"
393 401
         
394 402
         $fork = $this->events->fire("dispatcher.request.".$this->request_method, "REQUEST", $this->request);
395 403
 
396
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork;
404
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) {
405
+            $this->request = $fork;
406
+        }
397 407
 
398 408
         // Fire level3 event "dispatcher.request.[service]"
399 409
         
400 410
         $fork = $this->events->fire("dispatcher.request.".$this->request->getService(), "REQUEST", $this->request);
401 411
 
402
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) $this->request = $fork;
412
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ) {
413
+            $this->request = $fork;
414
+        }
403 415
 
404 416
         // Fire special event, it will not modify request
405 417
 
@@ -426,7 +438,9 @@  discard block
 block discarded – undo
426 438
 
427 439
         $fork = $this->events->fire("dispatcher.routingtable", "TABLE", $this->routingtable);
428 440
 
429
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable ) $this->routingtable = $fork;
441
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable ) {
442
+            $this->routingtable = $fork;
443
+        }
430 444
 
431 445
         // Retrieve current route from routing table
432 446
 
@@ -467,7 +481,9 @@  discard block
 block discarded – undo
467 481
             unset($preroute["parameters"]["ttl"]);
468 482
         }
469 483
         if ( isset($preroute["parameters"]["headers"]) ) {
470
-            if ( is_array($preroute["parameters"]["headers"]) ) foreach ($preroute["parameters"]["headers"] as $header => $value) $this->serviceroute->setHeader($header, $value);
484
+            if ( is_array($preroute["parameters"]["headers"]) ) {
485
+                foreach ($preroute["parameters"]["headers"] as $header => $value) $this->serviceroute->setHeader($header, $value);
486
+            }
471 487
             unset($preroute["parameters"]["headers"]);
472 488
         }
473 489
         if ( isset($preroute["parameters"]["accessControl"]) ) {
@@ -486,15 +502,21 @@  discard block
 block discarded – undo
486 502
 
487 503
         $fork = $this->events->fire("dispatcher.serviceroute", "ROUTE", $this->serviceroute);
488 504
 
489
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork;
505
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) {
506
+            $this->serviceroute = $fork;
507
+        }
490 508
 
491 509
         $fork = $this->events->fire("dispatcher.serviceroute.".$this->serviceroute->getType(), "ROUTE", $this->serviceroute);
492 510
 
493
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork;
511
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) {
512
+            $this->serviceroute = $fork;
513
+        }
494 514
 
495 515
         $fork = $this->events->fire("dispatcher.serviceroute.".$this->serviceroute->getService(), "ROUTE", $this->serviceroute);
496 516
 
497
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) $this->serviceroute = $fork;
517
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ) {
518
+            $this->serviceroute = $fork;
519
+        }
498 520
 
499 521
         // Fire special event, it will not modify route
500 522
 
@@ -621,7 +643,9 @@  discard block
 block discarded – undo
621 643
             $scr = explode('/', $_SERVER['SCRIPT_NAME']);
622 644
 
623 645
             for($i= 0;$i < sizeof($scr);$i++) {
624
-                if ($uri[$i] == $scr[$i]) unset($uri[$i]);
646
+                if ($uri[$i] == $scr[$i]) {
647
+                    unset($uri[$i]);
648
+                }
625 649
             }
626 650
 
627 651
             $service_matrix = array_values($uri);
@@ -634,16 +658,14 @@  discard block
 block discarded – undo
634 658
 
635 659
                 $service_attributes = empty($last) ? array_slice($service_matrix, 1, -1) : array_slice($service_matrix, 1);
636 660
 
637
-            }
638
-            else {
661
+            } else {
639 662
 
640 663
                 $service_requested = "default";
641 664
                 $service_attributes = Array();
642 665
 
643 666
             }
644 667
 
645
-        }
646
-        else {
668
+        } else {
647 669
 
648 670
             $service_matrix = $_GET;
649 671
 
@@ -653,8 +675,7 @@  discard block
 block discarded – undo
653 675
                 unset($service_matrix["service"]);
654 676
                 $service_attributes = $service_matrix;
655 677
 
656
-            }
657
-            else {
678
+            } else {
658 679
 
659 680
                 $service_requested = "";
660 681
                 $service_attributes = Array();
@@ -698,9 +719,9 @@  discard block
 block discarded – undo
698 719
 
699 720
         $http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://';
700 721
 
701
-        if ( is_null($service) ) $uri = "";
702
-
703
-        else {
722
+        if ( is_null($service) ) {
723
+            $uri = "";
724
+        } else {
704 725
 
705 726
             $self = $_SERVER['PHP_SELF'];
706 727
 
@@ -755,7 +776,9 @@  discard block
 block discarded – undo
755 776
 
756 777
     private function attributesMatch($provided, $expected, $liked) {
757 778
 
758
-        if ( $this->working_mode == "STANDARD" ) return $this->parametersMatch($provided, $expected, $liked);
779
+        if ( $this->working_mode == "STANDARD" ) {
780
+            return $this->parametersMatch($provided, $expected, $liked);
781
+        }
759 782
 
760 783
         $attributes = Array();
761 784
 
@@ -763,15 +786,13 @@  discard block
 block discarded – undo
763 786
         $esize = sizeof($expected);
764 787
         $lsize = sizeof($liked);
765 788
 
766
-        if ( $psize < $esize ) throw new DispatcherException("Conversation error", 400);
767
-
768
-        else if ( $psize == $esize ) {
789
+        if ( $psize < $esize ) {
790
+            throw new DispatcherException("Conversation error", 400);
791
+        } else if ( $psize == $esize ) {
769 792
 
770 793
             $attributes = $psize == 0 ? array() : array_combine($expected, $provided);
771 794
 
772
-        }
773
-
774
-        else {
795
+        } else {
775 796
 
776 797
             if ( $esize == 0 ) {
777 798
 
@@ -797,13 +818,11 @@  discard block
 block discarded – undo
797 818
 
798 819
                 $l_attributes = array_combine(array_slice($liked, 0, $lvaluessize), $lvalues);
799 820
 
800
-            }
801
-            else if ( $lvaluessize == $lsize ) {
821
+            } else if ( $lvaluessize == $lsize ) {
802 822
 
803 823
                 $l_attributes = $lvaluessize == 0 ? array() : array_combine($liked, $lvalues);
804 824
 
805
-            }
806
-            else {
825
+            } else {
807 826
 
808 827
                 if ( $lsize == 0 ) {
809 828
 
@@ -833,7 +852,9 @@  discard block
 block discarded – undo
833 852
 
834 853
         foreach ($expected as $parameter) {
835 854
 
836
-            if ( !isset($provided[$parameter]) ) throw new DispatcherException("Conversation error", 400);
855
+            if ( !isset($provided[$parameter]) ) {
856
+                throw new DispatcherException("Conversation error", 400);
857
+            }
837 858
 
838 859
         }
839 860
 
@@ -873,13 +894,17 @@  discard block
 block discarded – undo
873 894
 
874 895
         // If there's no cache for this request, use routing information to find service
875 896
 
876
-        if ( (include($target)) === false ) throw new DispatcherException("Cannot run service", 500);
897
+        if ( (include($target)) === false ) {
898
+            throw new DispatcherException("Cannot run service", 500);
899
+        }
877 900
 
878 901
         // Find a service implementation and try to init it
879 902
 
880 903
         $service_class = $route->getClass();
881 904
 
882
-        if ( empty($service_class) ) throw new DispatcherException("Cannot run service", 500);
905
+        if ( empty($service_class) ) {
906
+            throw new DispatcherException("Cannot run service", 500);
907
+        }
883 908
 
884 909
         $service_class = "\\Comodojo\\Dispatcher\\Service\\".$service_class;
885 910
 
@@ -1006,13 +1031,17 @@  discard block
 block discarded – undo
1006 1031
 
1007 1032
         $fork = $this->events->fire("dispatcher.result", "RESULT", $route);
1008 1033
 
1009
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork;
1034
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) {
1035
+            $route = $fork;
1036
+        }
1010 1037
 
1011 1038
         // Fire second hook (level2), as specified above
1012 1039
 
1013 1040
         $fork = $this->events->fire($hook, "RESULT", $route);
1014 1041
 
1015
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork;
1042
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) {
1043
+            $route = $fork;
1044
+        }
1016 1045
 
1017 1046
         // Now select and fire last hook (level3)
1018 1047
         // This means that event engine will fire something like "dispatcher.route.200"
@@ -1020,13 +1049,17 @@  discard block
 block discarded – undo
1020 1049
 
1021 1050
         $fork = $this->events->fire($hook.".".$route->getStatusCode(), "RESULT", $route);
1022 1051
 
1023
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork;
1052
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) {
1053
+            $route = $fork;
1054
+        }
1024 1055
 
1025 1056
         // Fire special event, it may modify result
1026 1057
 
1027 1058
         $fork = $this->events->fire("dispatcher.result.#", "RESULT", $route);
1028 1059
 
1029
-        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) $route = $fork;
1060
+        if ( $fork instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ) {
1061
+            $route = $fork;
1062
+        }
1030 1063
 
1031 1064
         // After hooks:
1032 1065
         // - store cache
@@ -1048,7 +1081,9 @@  discard block
 block discarded – undo
1048 1081
 
1049 1082
         $this->header->free();
1050 1083
 
1051
-        if ( $cache == "CLIENT" OR $cache == "BOTH" ) $this->header->setClientCache($this->serviceroute->getTtl());
1084
+        if ( $cache == "CLIENT" OR $cache == "BOTH" ) {
1085
+            $this->header->setClientCache($this->serviceroute->getTtl());
1086
+        }
1052 1087
 
1053 1088
         $this->header->setContentType($route->getContentType(), $route->getCharset());
1054 1089
 
Please login to merge, or discard this patch.
src/Events.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,6 +47,7 @@  discard block
 block discarded – undo
47 47
      * It does nothing special: called at boot time, only notify that events
48 48
      * are ready.
49 49
      *
50
+     * @param Debug $logger
50 51
      * @return null
51 52
      */
52 53
     final public function __construct($logger) {
@@ -66,7 +67,7 @@  discard block
 block discarded – undo
66 67
      * @param   string  $callback   Callback (or callback class)
67 68
      * @param   string  $method     (optional) callback method
68 69
      *
69
-     * @return  Object  $this
70
+     * @return  Events  $this
70 71
      */
71 72
     final public function add($event, $callback, $method=null) {
72 73
 
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
      *
69 69
      * @return  Object  $this
70 70
      */
71
-    final public function add($event, $callback, $method=null) {
71
+    final public function add($event, $callback, $method = null) {
72 72
 
73
-        if ( is_null($method) ) {
73
+        if (is_null($method)) {
74 74
 
75
-            if ( isset($this->hooks[$event]) ) array_push($this->hooks[$event], $callback);
75
+            if (isset($this->hooks[$event])) array_push($this->hooks[$event], $callback);
76 76
 
77 77
             else $this->hooks[$event] = Array($callback);
78 78
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 
81 81
         else {
82 82
 
83
-            if ( isset($this->hooks[$event]) ) array_push($this->hooks[$event], Array($callback, $method));
83
+            if (isset($this->hooks[$event])) array_push($this->hooks[$event], Array($callback, $method));
84 84
 
85 85
             else $this->hooks[$event] = Array(Array($callback, $method));
86 86
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
      *
103 103
      * @return  bool
104 104
      */
105
-    final public function remove($event, $callback=null) {
105
+    final public function remove($event, $callback = null) {
106 106
 
107
-        if ( is_null($callback) AND isset($this->hooks[$event]) ) {
107
+        if (is_null($callback) AND isset($this->hooks[$event])) {
108 108
 
109 109
             unset($this->hooks[$event]);
110 110
 
@@ -112,13 +112,13 @@  discard block
 block discarded – undo
112 112
 
113 113
         }
114 114
 
115
-        else if ( isset($this->hooks[$event]) ) {
115
+        else if (isset($this->hooks[$event])) {
116 116
 
117 117
             foreach ($this->hooks[$event] as $key => $hook) {
118 118
 
119
-                if ( is_array($hook) ) {
119
+                if (is_array($hook)) {
120 120
 
121
-                    if ( $hook[0] == $callback ) {
121
+                    if ($hook[0] == $callback) {
122 122
 
123 123
                         unset($this->hooks[$event][$key]);
124 124
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
                 }
130 130
                 else {
131 131
 
132
-                    if ( $hook == $callback ) {
132
+                    if ($hook == $callback) {
133 133
 
134 134
                         unset($this->hooks[$event][$key]);
135 135
 
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
 
167 167
         $value = $data;
168 168
 
169
-        if ( isset($this->hooks[$event]) ) {
169
+        if (isset($this->hooks[$event])) {
170 170
 
171
-            foreach($this->hooks[$event] as $callback) {
171
+            foreach ($this->hooks[$event] as $callback) {
172 172
 
173 173
                 $return_value = null;
174 174
 
175
-                if ( is_array($callback) ) {
175
+                if (is_array($callback)) {
176 176
 
177
-                    if ( is_callable(Array($callback[0], $callback[1])) ) {
177
+                    if (is_callable(Array($callback[0], $callback[1]))) {
178 178
 
179 179
                         try {
180 180
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
                 }
211 211
                 else {
212 212
 
213
-                    if ( is_callable($callback) ) {
213
+                    if (is_callable($callback)) {
214 214
 
215 215
                         try {
216 216
 
Please login to merge, or discard this patch.
Braces   +18 added lines, -22 removed lines patch added patch discarded remove patch
@@ -72,17 +72,19 @@  discard block
 block discarded – undo
72 72
 
73 73
         if ( is_null($method) ) {
74 74
 
75
-            if ( isset($this->hooks[$event]) ) array_push($this->hooks[$event], $callback);
76
-
77
-            else $this->hooks[$event] = Array($callback);
78
-
79
-        }
80
-
81
-        else {
75
+            if ( isset($this->hooks[$event]) ) {
76
+                array_push($this->hooks[$event], $callback);
77
+            } else {
78
+                $this->hooks[$event] = Array($callback);
79
+            }
82 80
 
83
-            if ( isset($this->hooks[$event]) ) array_push($this->hooks[$event], Array($callback, $method));
81
+        } else {
84 82
 
85
-            else $this->hooks[$event] = Array(Array($callback, $method));
83
+            if ( isset($this->hooks[$event]) ) {
84
+                array_push($this->hooks[$event], Array($callback, $method));
85
+            } else {
86
+                $this->hooks[$event] = Array(Array($callback, $method));
87
+            }
86 88
 
87 89
         }
88 90
 
@@ -110,9 +112,7 @@  discard block
 block discarded – undo
110 112
 
111 113
             return true;
112 114
 
113
-        }
114
-
115
-        else if ( isset($this->hooks[$event]) ) {
115
+        } else if ( isset($this->hooks[$event]) ) {
116 116
 
117 117
             foreach ($this->hooks[$event] as $key => $hook) {
118 118
 
@@ -126,8 +126,7 @@  discard block
 block discarded – undo
126 126
 
127 127
                     }
128 128
 
129
-                }
130
-                else {
129
+                } else {
131 130
 
132 131
                     if ( $hook == $callback ) {
133 132
 
@@ -143,10 +142,10 @@  discard block
 block discarded – undo
143 142
 
144 143
             return false;
145 144
 
145
+        } else {
146
+            return false;
146 147
         }
147 148
 
148
-        else return false;
149
-
150 149
     }
151 150
 
152 151
     /**
@@ -194,8 +193,7 @@  discard block
 block discarded – undo
194 193
 
195 194
                         }
196 195
 
197
-                    }
198
-                    else {
196
+                    } else {
199 197
 
200 198
                         $this->logger->warning('Skipping not-callable hook', array(
201 199
                             'EVENT'    => $event,
@@ -207,8 +205,7 @@  discard block
 block discarded – undo
207 205
 
208 206
                     }
209 207
 
210
-                }
211
-                else {
208
+                } else {
212 209
 
213 210
                     if ( is_callable($callback) ) {
214 211
 
@@ -229,8 +226,7 @@  discard block
 block discarded – undo
229 226
 
230 227
                         }
231 228
 
232
-                    }
233
-                    else {
229
+                    } else {
234 230
 
235 231
                         $this->logger->warning('Skipping not-callable hook', array(
236 232
                             'EVENT'    => $event,
Please login to merge, or discard this patch.
src/Header.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
      * Set $header with a $value. If value is null, only $header will be used
58 58
      *
59 59
      * @param   string  $header   Header name
60
-     * @param   mixed   $value    Header value (if not included in $header)
61
-     * @return  Object  $this
60
+     * @param   string   $value    Header value (if not included in $header)
61
+     * @return  Header  $this
62 62
      */
63 63
     final public function set($header, $value=null) {
64 64
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     /**
87 87
      * Free recorded headers (re-init array)
88 88
      *
89
-     * @return  Object  $this
89
+     * @return  Header  $this
90 90
      */
91 91
     final public function free() {
92 92
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * Shortcut to set client cache headers
232 232
      *
233 233
      * @param   integer     $ttl    Cache time to live
234
-     * @return  Object      $this
234
+     * @return  Header      $this
235 235
      */
236 236
     public function setClientCache($ttl) {
237 237
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
      *
256 256
      * @param   string      $type       Content type
257 257
      * @param   string      $charset    Charset
258
-     * @return  Object      $this
258
+     * @return  Header      $this
259 259
      */
260 260
     public function setContentType($type, $charset=null) {
261 261
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      *
48 48
      * @param   string  $time   Dispatcher time
49 49
      */
50
-    final public function __construct($time=false) {
50
+    final public function __construct($time = false) {
51 51
 
52 52
         $this->current_time = $time !== false ? $time : microtime(true);
53 53
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      * @param   mixed   $value    Header value (if not included in $header)
61 61
      * @return  Object  $this
62 62
      */
63
-    final public function set($header, $value=null) {
63
+    final public function set($header, $value = null) {
64 64
 
65 65
         $this->headers[$header] = $value;
66 66
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      */
78 78
     final public function get($header) {
79 79
 
80
-        if ( array_key_exists($header, $this->headers) ) return $this->headers[$header];
80
+        if (array_key_exists($header, $this->headers)) return $this->headers[$header];
81 81
 
82 82
         else return null;
83 83
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      * @param   integer     $contentLength  Content length
114 114
      * @param   string      $value          (optional) value (see method description)
115 115
      */
116
-    final public function compose($status, $contentLength=0, $value=false) {
116
+    final public function compose($status, $contentLength = 0, $value = false) {
117 117
 
118 118
         switch ($status) {
119 119
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 
146 146
             header($_SERVER["SERVER_PROTOCOL"].' 204 No Content');
147 147
             header('Status: 204 No Content');
148
-            header('Content-Length: 0',true);
148
+            header('Content-Length: 0', true);
149 149
 
150 150
             $this->processExtraHeaders($this->headers);
151 151
             
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
             case 303: //See Other
158 158
             case 307: //Temporary Redirect
159 159
 
160
-            header("Location: ".$value,true,$status);
160
+            header("Location: ".$value, true, $status);
161 161
             
162 162
             break;
163 163
 
164 164
             case 304: //Not Modified
165 165
 
166
-            if ( $value === false ) header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified');
166
+            if ($value === false) header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified');
167 167
             else header('Last-Modified: '.gmdate('D, d M Y H:i:s', $value).' GMT', true, 304);
168 168
 
169 169
                 if ($contentLength !== 0) header('Content-Length: '.$contentLength); //is it needed?
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 
198 198
             case 405: //Not allowed
199 199
 
200
-            header('Allow: ' . $value, true, 405); 
200
+            header('Allow: '.$value, true, 405); 
201 201
 
202 202
             break;
203 203
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 
210 210
             case 501: //Not implemented
211 211
 
212
-            header('Allow: ' . $value, true, 501);
212
+            header('Allow: '.$value, true, 501);
213 213
             
214 214
             break;
215 215
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 
218 218
             header('HTTP/1.1 503 Service Temporarily Unavailable');
219 219
             header('Status: 503 Service Temporarily Unavailable');
220
-            if ( $value !== false AND @is_int($value) ) {
220
+            if ($value !== false AND @is_int($value)) {
221 221
                 header('Retry-After: '.$value);
222 222
             }
223 223
             
@@ -237,13 +237,13 @@  discard block
 block discarded – undo
237 237
 
238 238
         $ttl = filter_var($ttl, FILTER_VALIDATE_INT);
239 239
 
240
-        if ( $ttl > 0 ) {
241
-            $this->set("Cache-Control","max-age=".$ttl.", must-revalidate");
242
-            $this->set("Expires",gmdate("D, d M Y H:i:s", (int)$this->current_time + $ttl)." GMT");
240
+        if ($ttl > 0) {
241
+            $this->set("Cache-Control", "max-age=".$ttl.", must-revalidate");
242
+            $this->set("Expires", gmdate("D, d M Y H:i:s", (int)$this->current_time+$ttl)." GMT");
243 243
         }
244 244
         else {
245
-            $this->set("Cache-Control","no-cache, must-revalidate");
246
-            $this->set("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
245
+            $this->set("Cache-Control", "no-cache, must-revalidate");
246
+            $this->set("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
247 247
         }
248 248
 
249 249
         return $this;
@@ -257,11 +257,11 @@  discard block
 block discarded – undo
257 257
      * @param   string      $charset    Charset
258 258
      * @return  Object      $this
259 259
      */
260
-    public function setContentType($type, $charset=null) {
260
+    public function setContentType($type, $charset = null) {
261 261
 
262 262
 
263
-        if ( is_null($charset) ) $this->set("Content-type",strtolower($type));
264
-        else $this->set("Content-type",strtolower($type)."; charset=".$charset);
263
+        if (is_null($charset)) $this->set("Content-type", strtolower($type));
264
+        else $this->set("Content-type", strtolower($type)."; charset=".$charset);
265 265
 
266 266
         return $this;
267 267
 
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
      */
299 299
     private function processExtraHeaders($headers) {
300 300
 
301
-        foreach ( $headers as $header => $value ) {
301
+        foreach ($headers as $header => $value) {
302 302
 
303
-            if ( is_null($value) ) header($header, true);
303
+            if (is_null($value)) header($header, true);
304 304
             else  header($header.": ".$value, true);
305 305
 
306 306
         }
Please login to merge, or discard this patch.
Braces   +31 added lines, -16 removed lines patch added patch discarded remove patch
@@ -77,9 +77,11 @@  discard block
 block discarded – undo
77 77
      */
78 78
     final public function get($header) {
79 79
 
80
-        if ( array_key_exists($header, $this->headers) ) return $this->headers[$header];
81
-
82
-        else return null;
80
+        if ( array_key_exists($header, $this->headers) ) {
81
+            return $this->headers[$header];
82
+        } else {
83
+            return null;
84
+        }
83 85
 
84 86
     }
85 87
 
@@ -163,10 +165,16 @@  discard block
 block discarded – undo
163 165
 
164 166
             case 304: //Not Modified
165 167
 
166
-            if ( $value === false ) header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified');
167
-            else header('Last-Modified: '.gmdate('D, d M Y H:i:s', $value).' GMT', true, 304);
168
+            if ( $value === false ) {
169
+                header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified');
170
+            } else {
171
+                header('Last-Modified: '.gmdate('D, d M Y H:i:s', $value).' GMT', true, 304);
172
+            }
168 173
 
169
-                if ($contentLength !== 0) header('Content-Length: '.$contentLength); //is it needed?
174
+                if ($contentLength !== 0) {
175
+                    header('Content-Length: '.$contentLength);
176
+                }
177
+                //is it needed?
170 178
 
171 179
                 $this->processExtraHeaders($this->headers);
172 180
 
@@ -240,8 +248,7 @@  discard block
 block discarded – undo
240 248
         if ( $ttl > 0 ) {
241 249
             $this->set("Cache-Control","max-age=".$ttl.", must-revalidate");
242 250
             $this->set("Expires",gmdate("D, d M Y H:i:s", (int)$this->current_time + $ttl)." GMT");
243
-        }
244
-        else {
251
+        } else {
245 252
             $this->set("Cache-Control","no-cache, must-revalidate");
246 253
             $this->set("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
247 254
         }
@@ -260,8 +267,11 @@  discard block
 block discarded – undo
260 267
     public function setContentType($type, $charset=null) {
261 268
 
262 269
 
263
-        if ( is_null($charset) ) $this->set("Content-type",strtolower($type));
264
-        else $this->set("Content-type",strtolower($type)."; charset=".$charset);
270
+        if ( is_null($charset) ) {
271
+            $this->set("Content-type",strtolower($type));
272
+        } else {
273
+            $this->set("Content-type",strtolower($type)."; charset=".$charset);
274
+        }
265 275
 
266 276
         return $this;
267 277
 
@@ -276,13 +286,15 @@  discard block
 block discarded – undo
276 286
 
277 287
         $headers = '';
278 288
 
279
-        if (function_exists('getallheaders')) $headers = getallheaders();
280
-
281
-        else {
289
+        if (function_exists('getallheaders')) {
290
+            $headers = getallheaders();
291
+        } else {
282 292
 
283 293
             foreach ($_SERVER as $name => $value) {
284 294
 
285
-                if (substr($name, 0, 5) == 'HTTP_') $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
295
+                if (substr($name, 0, 5) == 'HTTP_') {
296
+                    $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
297
+                }
286 298
             }
287 299
 
288 300
         }
@@ -300,8 +312,11 @@  discard block
 block discarded – undo
300 312
 
301 313
         foreach ( $headers as $header => $value ) {
302 314
 
303
-            if ( is_null($value) ) header($header, true);
304
-            else  header($header.": ".$value, true);
315
+            if ( is_null($value) ) {
316
+                header($header, true);
317
+            } else {
318
+                header($header.": ".$value, true);
319
+            }
305 320
 
306 321
         }
307 322
 
Please login to merge, or discard this patch.
src/ObjectRoute/ObjectRoute.php 3 patches
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      *
61 61
      * @param   string  $service    The service name
62 62
      *
63
-     * @return  Object  $this
63
+     * @return  ObjectRoute  $this
64 64
      */
65 65
     public function setService($service) {
66 66
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      *
86 86
      * @param   string  $type
87 87
      *
88
-     * @return  Object  $this
88
+     * @return  ObjectRoute  $this
89 89
      */
90 90
     public function setType($type) {
91 91
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @param   string  $target
115 115
      *
116
-     * @return  Object  $this
116
+     * @return  ObjectRoute  $this
117 117
      */
118 118
     public function setTarget($target) {
119 119
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
      * @param   string  $header     Header name
240 240
      * @param   string  $value      Header content (optional)
241 241
      *
242
-     * @return  ObjectRequest   $this
242
+     * @return  ObjectRoute   $this
243 243
      */
244 244
     public function setHeader($header, $value=null) {
245 245
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      *
291 291
      * @param   array   $headers    Headers array
292 292
      *
293
-     * @return  ObjectRequest   $this
293
+     * @return  ObjectRoute   $this
294 294
      */
295 295
     public function setHeaders($headers) {
296 296
 
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     /**
304 304
      * Unset headers
305 305
      *
306
-     * @return  ObjectRequest   $this
306
+     * @return  ObjectRoute   $this
307 307
      */
308 308
     public function unsetHeaders() {
309 309
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     /**
328 328
      * Set extra parameter
329 329
      *
330
-     * @return  ObjectRequest   $this
330
+     * @return  ObjectRoute   $this
331 331
      */
332 332
     public function setParameter($parameter, $value=null) {
333 333
 
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -47,13 +47,13 @@  discard block
 block discarded – undo
47 47
 
48 48
     private $parameters = array();
49 49
 
50
-    private $supported_route_types = array("ROUTE","REDIRECT","ERROR");
50
+    private $supported_route_types = array("ROUTE", "REDIRECT", "ERROR");
51 51
 
52
-    private $supported_redirect_codes = array(201,301,302,303,307);
52
+    private $supported_redirect_codes = array(201, 301, 302, 303, 307);
53 53
 
54
-    private $supported_error_codes = array(400,403,404,405,500,501,503);
54
+    private $supported_error_codes = array(400, 403, 404, 405, 500, 501, 503);
55 55
 
56
-    private $supported_cache_modes = array("SERVER","CLIENT","BOTH");
56
+    private $supported_cache_modes = array("SERVER", "CLIENT", "BOTH");
57 57
 
58 58
     /**
59 59
      * Set service name
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      *
242 242
      * @return  ObjectRequest   $this
243 243
      */
244
-    public function setHeader($header, $value=null) {
244
+    public function setHeader($header, $value = null) {
245 245
 
246 246
         $this->headers[$header] = $value;
247 247
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public function unsetHeader($header) {
260 260
 
261
-        if ( isset($this->headers[$header]) ) {
261
+        if (isset($this->headers[$header])) {
262 262
 
263 263
             unset($this->headers[$header]);
264 264
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      */
280 280
     public function getHeader($header) {
281 281
 
282
-        if ( isset($this->headers[$header]) ) return $this->headers[$header];
282
+        if (isset($this->headers[$header])) return $this->headers[$header];
283 283
 
284 284
         return null;
285 285
 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
      *
330 330
      * @return  ObjectRequest   $this
331 331
      */
332
-    public function setParameter($parameter, $value=null) {
332
+    public function setParameter($parameter, $value = null) {
333 333
 
334 334
         $this->parameters[$parameter] = $value;
335 335
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      */
345 345
     public function getParameter($parameter) {
346 346
 
347
-        if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter];
347
+        if (isset($this->parameters[$parameter])) return $this->parameters[$parameter];
348 348
 
349 349
         else return null;
350 350
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -186,8 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
             $this->cache = false;
188 188
 
189
-        }
190
-        else {
189
+        } else {
191 190
 
192 191
             $cache = strtoupper($cache);
193 192
 
@@ -279,7 +278,9 @@  discard block
 block discarded – undo
279 278
      */
280 279
     public function getHeader($header) {
281 280
 
282
-        if ( isset($this->headers[$header]) ) return $this->headers[$header];
281
+        if ( isset($this->headers[$header]) ) {
282
+            return $this->headers[$header];
283
+        }
283 284
 
284 285
         return null;
285 286
 
@@ -344,9 +345,11 @@  discard block
 block discarded – undo
344 345
      */
345 346
     public function getParameter($parameter) {
346 347
 
347
-        if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter];
348
-
349
-        else return null;
348
+        if ( isset($this->parameters[$parameter]) ) {
349
+            return $this->parameters[$parameter];
350
+        } else {
351
+            return null;
352
+        }
350 353
 
351 354
     }
352 355
 
Please login to merge, or discard this patch.
src/Service/Service.php 3 patches
Doc Comments   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      * @param   array   $attributes array og attributes that service expects
261 261
      * @param   array   $parameters array of parameters that service expects
262 262
      *
263
-     * @return  Object  $this
263
+     * @return  Service  $this
264 264
      */
265 265
     final public function expects($method, $attributes, $parameters=array()) {
266 266
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
      * @param   array   $attributes array og attributes that service likes
281 281
      * @param   array   $parameters array of parameters that service likes
282 282
      *
283
-     * @return  Object  $this
283
+     * @return  Service  $this
284 284
      */
285 285
     final public function likes($method, $attributes, $parameters=array()) {
286 286
 
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
      *
307 307
      * @param   string  $methods     HTTP methods, comma separated
308 308
      *
309
-     * @return  Object  $this
309
+     * @return  Service  $this
310 310
      */
311 311
     final public function setSupportedMethods($methods) {
312 312
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
      * Set service content type
332 332
      *
333 333
      * @param   string  $type   Content Type
334
-     * @return  Object  $this
334
+     * @return  Service  $this
335 335
      */
336 336
     final public function setContentType($type) {
337 337
 
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
      *
358 358
      * @param   string  $charset   Charset
359 359
      *
360
-     * @return  Object  $this
360
+     * @return  Service  $this
361 361
      */
362 362
     final public function setCharset($charset) {
363 363
 
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
      * Set success status code
383 383
      *
384 384
      * @param   integer $code   HTTP status code (in case of success)
385
-     * @return  Object  $this
385
+     * @return  Service  $this
386 386
      */
387 387
     final public function setStatusCode($code) {
388 388
 
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
      * @param   string  $header     Header name
434 434
      * @param   string  $value      Header content (optional)
435 435
      *
436
-     * @return  Object  $this
436
+     * @return  Service  $this
437 437
      */
438 438
     final public function setHeader($header, $value=null) {
439 439
 
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
      *
485 485
      * @param   array   $headers    Headers array
486 486
      *
487
-     * @return  Object  $this
487
+     * @return  Service  $this
488 488
      */
489 489
     final public function setHeaders($headers) {
490 490
 
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
     /**
498 498
      * Unset headers
499 499
      *
500
-     * @return  Object  $this
500
+     * @return  Service  $this
501 501
      */
502 502
     final public function unsetHeaders() {
503 503
 
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
     /**
522 522
      * Get service-supported HTTP methods
523 523
      *
524
-     * @return  array   Headers array
524
+     * @return  string   Headers array
525 525
      */
526 526
     final public function getSupportedMethods() {
527 527
 
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
     /**
556 556
      * Return the callable class method that reflect the requested one
557 557
      *
558
-     * @return  array   Headers array
558
+     * @return  string   Headers array
559 559
      */
560 560
     final public function getCallableMethod($method) {
561 561
 
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
      *
178 178
      * @var     array
179 179
      */
180
-    private $supported_success_codes = array(200,202,204);
180
+    private $supported_success_codes = array(200, 202, 204);
181 181
 
182 182
     /*************** HTTP METHODS IMPLEMENTATIONS **************/
183 183
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      *
263 263
      * @return  Object  $this
264 264
      */
265
-    final public function expects($method, $attributes, $parameters=array()) {
265
+    final public function expects($method, $attributes, $parameters = array()) {
266 266
 
267 267
         $method = strtoupper($method);
268 268
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
      *
283 283
      * @return  Object  $this
284 284
      */
285
-    final public function likes($method, $attributes, $parameters=array()) {
285
+    final public function likes($method, $attributes, $parameters = array()) {
286 286
 
287 287
         $method = strtoupper($method);
288 288
 
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
      *
436 436
      * @return  Object  $this
437 437
      */
438
-    final public function setHeader($header, $value=null) {
438
+    final public function setHeader($header, $value = null) {
439 439
 
440 440
         $this->headers[$header] = $value;
441 441
 
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
      */
453 453
     final public function unsetHeader($header) {
454 454
 
455
-        if ( isset($this->headers[$header]) ) {
455
+        if (isset($this->headers[$header])) {
456 456
 
457 457
             unset($this->headers[$header]);
458 458
 
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
      */
474 474
     final public function getHeader($header) {
475 475
 
476
-        if ( isset($this->headers[$header]) ) return $this->headers[$header];
476
+        if (isset($this->headers[$header])) return $this->headers[$header];
477 477
 
478 478
         return null;
479 479
 
@@ -536,15 +536,15 @@  discard block
 block discarded – undo
536 536
      */
537 537
     final public function getImplementedMethods() {
538 538
 
539
-        if ( method_exists($this, 'any') ) return explode(",",$this->supported_http_methods);
539
+        if (method_exists($this, 'any')) return explode(",", $this->supported_http_methods);
540 540
 
541
-        $supported_methods = explode(',',$this->supported_http_methods);
541
+        $supported_methods = explode(',', $this->supported_http_methods);
542 542
 
543 543
         $implemented_methods = array();
544 544
 
545
-        foreach ( $supported_methods as $method ) {
545
+        foreach ($supported_methods as $method) {
546 546
 
547
-            if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method);
547
+            if (method_exists($this, strtolower($method))) array_push($implemented_methods, $method);
548 548
 
549 549
         }
550 550
 
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
      */
560 560
     final public function getCallableMethod($method) {
561 561
 
562
-        if ( method_exists($this, strtolower($method)) ) return strtolower($method);
562
+        if (method_exists($this, strtolower($method))) return strtolower($method);
563 563
 
564 564
         else return "any";
565 565
 
@@ -576,9 +576,9 @@  discard block
 block discarded – undo
576 576
 
577 577
         return array(
578 578
 
579
-            ( sizeof($this->expected_attributes[$method]) == 0 AND sizeof($this->expected_attributes["ANY"]) != 0 ) ? $this->expected_attributes["ANY"] : $this->expected_attributes[$method],
579
+            (sizeof($this->expected_attributes[$method]) == 0 AND sizeof($this->expected_attributes["ANY"]) != 0) ? $this->expected_attributes["ANY"] : $this->expected_attributes[$method],
580 580
 
581
-            ( sizeof($this->expected_parameters[$method]) == 0 AND sizeof($this->expected_parameters["ANY"]) != 0 ) ? $this->expected_parameters["ANY"] : $this->expected_parameters[$method]
581
+            (sizeof($this->expected_parameters[$method]) == 0 AND sizeof($this->expected_parameters["ANY"]) != 0) ? $this->expected_parameters["ANY"] : $this->expected_parameters[$method]
582 582
 
583 583
         );
584 584
 
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
 
596 596
         return array(
597 597
 
598
-            ( sizeof($this->liked_attributes[$method]) == 0 AND sizeof($this->liked_attributes["ANY"]) != 0 ) ? $this->liked_attributes["ANY"] : $this->liked_attributes[$method],
598
+            (sizeof($this->liked_attributes[$method]) == 0 AND sizeof($this->liked_attributes["ANY"]) != 0) ? $this->liked_attributes["ANY"] : $this->liked_attributes[$method],
599 599
 
600
-            ( sizeof($this->liked_parameters[$method]) == 0 AND sizeof($this->liked_parameters["ANY"]) != 0 ) ? $this->liked_parameters["ANY"] : $this->liked_parameters[$method]
600
+            (sizeof($this->liked_parameters[$method]) == 0 AND sizeof($this->liked_parameters["ANY"]) != 0) ? $this->liked_parameters["ANY"] : $this->liked_parameters[$method]
601 601
 
602 602
             );
603 603
 
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
      */
634 634
     final public function getAttribute($attribute) {
635 635
 
636
-        if ( isset($this->attributes[$attribute]) ) return $this->attributes[$attribute];
636
+        if (isset($this->attributes[$attribute])) return $this->attributes[$attribute];
637 637
 
638 638
         return null;
639 639
 
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
      *
665 665
      * @return  array
666 666
      */
667
-    final public function getParameters($raw=false) {
667
+    final public function getParameters($raw = false) {
668 668
 
669 669
         return $raw ? $this->raw_parameters : $this->parameters;
670 670
 
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
      */
680 680
     final public function getParameter($parameter) {
681 681
 
682
-        if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter];
682
+        if (isset($this->parameters[$parameter])) return $this->parameters[$parameter];
683 683
 
684 684
         return null;
685 685
 
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
      */
705 705
     final public function getRequestHeader($header) {
706 706
 
707
-        if ( isset($this->request_headers[$header]) ) return $this->request_headers[$header];
707
+        if (isset($this->request_headers[$header])) return $this->request_headers[$header];
708 708
 
709 709
         return null;
710 710
 
Please login to merge, or discard this patch.
Braces   +23 added lines, -9 removed lines patch added patch discarded remove patch
@@ -473,7 +473,9 @@  discard block
 block discarded – undo
473 473
      */
474 474
     final public function getHeader($header) {
475 475
 
476
-        if ( isset($this->headers[$header]) ) return $this->headers[$header];
476
+        if ( isset($this->headers[$header]) ) {
477
+            return $this->headers[$header];
478
+        }
477 479
 
478 480
         return null;
479 481
 
@@ -536,7 +538,9 @@  discard block
 block discarded – undo
536 538
      */
537 539
     final public function getImplementedMethods() {
538 540
 
539
-        if ( method_exists($this, 'any') ) return explode(",",$this->supported_http_methods);
541
+        if ( method_exists($this, 'any') ) {
542
+            return explode(",",$this->supported_http_methods);
543
+        }
540 544
 
541 545
         $supported_methods = explode(',',$this->supported_http_methods);
542 546
 
@@ -544,7 +548,9 @@  discard block
 block discarded – undo
544 548
 
545 549
         foreach ( $supported_methods as $method ) {
546 550
 
547
-            if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method);
551
+            if ( method_exists($this, strtolower($method)) ) {
552
+                array_push($implemented_methods,$method);
553
+            }
548 554
 
549 555
         }
550 556
 
@@ -559,9 +565,11 @@  discard block
 block discarded – undo
559 565
      */
560 566
     final public function getCallableMethod($method) {
561 567
 
562
-        if ( method_exists($this, strtolower($method)) ) return strtolower($method);
563
-
564
-        else return "any";
568
+        if ( method_exists($this, strtolower($method)) ) {
569
+            return strtolower($method);
570
+        } else {
571
+            return "any";
572
+        }
565 573
 
566 574
     }
567 575
 
@@ -633,7 +641,9 @@  discard block
 block discarded – undo
633 641
      */
634 642
     final public function getAttribute($attribute) {
635 643
 
636
-        if ( isset($this->attributes[$attribute]) ) return $this->attributes[$attribute];
644
+        if ( isset($this->attributes[$attribute]) ) {
645
+            return $this->attributes[$attribute];
646
+        }
637 647
 
638 648
         return null;
639 649
 
@@ -679,7 +689,9 @@  discard block
 block discarded – undo
679 689
      */
680 690
     final public function getParameter($parameter) {
681 691
 
682
-        if ( isset($this->parameters[$parameter]) ) return $this->parameters[$parameter];
692
+        if ( isset($this->parameters[$parameter]) ) {
693
+            return $this->parameters[$parameter];
694
+        }
683 695
 
684 696
         return null;
685 697
 
@@ -704,7 +716,9 @@  discard block
 block discarded – undo
704 716
      */
705 717
     final public function getRequestHeader($header) {
706 718
 
707
-        if ( isset($this->request_headers[$header]) ) return $this->request_headers[$header];
719
+        if ( isset($this->request_headers[$header]) ) {
720
+            return $this->request_headers[$header];
721
+        }
708 722
 
709 723
         return null;
710 724
 
Please login to merge, or discard this patch.
src/XML.php 3 patches
Doc Comments   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      * 
117 117
      * @param bool $bool
118 118
      *
119
-     * @return Object $this
119
+     * @return XML $this
120 120
      */
121 121
     final public function setIncludeHeader($bool) {
122 122
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      * 
132 132
      * @param int $int
133 133
      *
134
-     * @return Object $this
134
+     * @return XML $this
135 135
      */
136 136
     final public function setCaseFolding($int) {
137 137
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      * 
147 147
      * @param int $int
148 148
      *
149
-     * @return Object $this
149
+     * @return XML $this
150 150
      */
151 151
     final public function setSkipWhite($int) {
152 152
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      * 
162 162
      * @param string $encoding
163 163
      *
164
-     * @return Object $this
164
+     * @return XML $this
165 165
      */
166 166
     final public function setEncoding($encoding) {
167 167
 
@@ -306,6 +306,7 @@  discard block
 block discarded – undo
306 306
     /**
307 307
      * Get element childs (if any)
308 308
      *
309
+     * @param integer $i
309 310
      * @return array
310 311
      */
311 312
     private function getChilds(&$i) {
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
      */
203 203
     public function encode(array $data) {
204 204
 
205
-        $structure = ($this->includeHeader ? $this->getHeader() : "") . $this->getParent();
205
+        $structure = ($this->includeHeader ? $this->getHeader() : "").$this->getParent();
206 206
         
207 207
         $this->ObjectXML = new SimpleXMLElement($structure);
208 208
         
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         
211 211
         $xml = $this->ObjectXML->asXML();
212 212
 
213
-        if ( $xml === false ) throw new XMLException("Error formatting object");
213
+        if ($xml === false) throw new XMLException("Error formatting object");
214 214
         
215 215
         return $xml;
216 216
         
@@ -221,17 +221,17 @@  discard block
 block discarded – undo
221 221
      * 
222 222
      * @return array    
223 223
      */
224
-    public function decode(string $xml, $encoding=null) {
224
+    public function decode(string $xml, $encoding = null) {
225 225
 
226 226
         $this->parser = is_null($encoding) ? xml_parser_create() : xml_parser_create($encoding);
227 227
 
228
-        xml_parser_set_option($this->parser,XML_OPTION_TARGET_ENCODING,$this->encoding);
229
-        xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,$this->caseFolding);
230
-        xml_parser_set_option($this->parser,XML_OPTION_SKIP_WHITE,$this->skipWhite);
228
+        xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->encoding);
229
+        xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, $this->caseFolding);
230
+        xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, $this->skipWhite);
231 231
         
232 232
         $parser_structs = xml_parse_into_struct($this->parser, $xml, $this->struct, $index);
233 233
         
234
-        if ( $parser_structs === 0 ) throw new XMLException("Failed to parse xml data into structs");
234
+        if ($parser_structs === 0) throw new XMLException("Failed to parse xml data into structs");
235 235
         
236 236
         $this->counter = count($this->struct);
237 237
 
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
      */
252 252
     private function sanitizeKeys($input, $key) {
253 253
 
254
-        $key_value = explode("_",$this->struct[$key]["tag"]);
254
+        $key_value = explode("_", $this->struct[$key]["tag"]);
255 255
 
256
-        if ( sizeof($key_value) == 2 AND $key_value[0] == "KEY" AND is_numeric($key_value[1]) ) {
256
+        if (sizeof($key_value) == 2 AND $key_value[0] == "KEY" AND is_numeric($key_value[1])) {
257 257
 
258 258
             $this->struct[$key]["tag"] = intval($key_value[1]);
259 259
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
      */
267 267
     private function free() {
268 268
 
269
-        if( isset($this->parser) AND @is_resource($this->parser) ) {
269
+        if (isset($this->parser) AND @is_resource($this->parser)) {
270 270
 
271 271
             xml_parser_free($this->parser);
272 272
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 
321 321
             $value = isset($this->struct[$i]["value"]) ? $this->struct[$i]["value"] : "";
322 322
 
323
-            switch($this->struct[$i]["type"]) {
323
+            switch ($this->struct[$i]["type"]) {
324 324
 
325 325
                 case "open":
326 326
                 $child = $this->getChilds($i);
@@ -348,13 +348,13 @@  discard block
 block discarded – undo
348 348
      */
349 349
     private function addNode($target, $key, $attributes, $child, $value) {
350 350
         
351
-        if ( !isset($target[$key]) ) {
351
+        if (!isset($target[$key])) {
352 352
             
353 353
             if ($child != "") $target[$key] = $child;
354 354
 
355
-            if ($attributes != "") foreach($attributes as $akey => $avalue) $target[$key][$akey] = $avalue;
355
+            if ($attributes != "") foreach ($attributes as $akey => $avalue) $target[$key][$akey] = $avalue;
356 356
 
357
-            else if ( $value != "" ) $target[$key] = $value;
357
+            else if ($value != "") $target[$key] = $value;
358 358
             
359 359
         } else {
360 360
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
                 $oldval = $target[$key];
364 364
                 $target[$key] = array();
365 365
                 $target[$key][0] = $oldval;
366
-                $index=1;
366
+                $index = 1;
367 367
 
368 368
             }
369 369
             else {
@@ -372,11 +372,11 @@  discard block
 block discarded – undo
372 372
 
373 373
             }
374 374
 
375
-            if ( $child != "" ) $target[$key][$index] = $child;
375
+            if ($child != "") $target[$key][$index] = $child;
376 376
 
377
-            if ( $attributes != "" ) foreach($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue;
377
+            if ($attributes != "") foreach ($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue;
378 378
 
379
-            elseif ( $value != "" ) $target[$key][$index] = $value;
379
+            elseif ($value != "") $target[$key][$index] = $value;
380 380
         }
381 381
 
382 382
         return $target;
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 
394 394
         foreach ($data as $key => $value) {
395 395
 
396
-            if ( is_array($value) ) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value);
396
+            if (is_array($value)) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value);
397 397
 
398 398
             else $ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key, mb_convert_encoding($value, $this->encoding));
399 399
 
Please login to merge, or discard this patch.
Braces   +28 added lines, -15 removed lines patch added patch discarded remove patch
@@ -210,7 +210,9 @@  discard block
 block discarded – undo
210 210
         
211 211
         $xml = $this->ObjectXML->asXML();
212 212
 
213
-        if ( $xml === false ) throw new XMLException("Error formatting object");
213
+        if ( $xml === false ) {
214
+            throw new XMLException("Error formatting object");
215
+        }
214 216
         
215 217
         return $xml;
216 218
         
@@ -231,7 +233,9 @@  discard block
 block discarded – undo
231 233
         
232 234
         $parser_structs = xml_parse_into_struct($this->parser, $xml, $this->struct, $index);
233 235
         
234
-        if ( $parser_structs === 0 ) throw new XMLException("Failed to parse xml data into structs");
236
+        if ( $parser_structs === 0 ) {
237
+            throw new XMLException("Failed to parse xml data into structs");
238
+        }
235 239
         
236 240
         $this->counter = count($this->struct);
237 241
 
@@ -350,11 +354,15 @@  discard block
 block discarded – undo
350 354
         
351 355
         if ( !isset($target[$key]) ) {
352 356
             
353
-            if ($child != "") $target[$key] = $child;
354
-
355
-            if ($attributes != "") foreach($attributes as $akey => $avalue) $target[$key][$akey] = $avalue;
357
+            if ($child != "") {
358
+                $target[$key] = $child;
359
+            }
356 360
 
357
-            else if ( $value != "" ) $target[$key] = $value;
361
+            if ($attributes != "") {
362
+                foreach($attributes as $akey => $avalue) $target[$key][$akey] = $avalue;
363
+            } else if ( $value != "" ) {
364
+                $target[$key] = $value;
365
+            }
358 366
             
359 367
         } else {
360 368
 
@@ -365,18 +373,21 @@  discard block
 block discarded – undo
365 373
                 $target[$key][0] = $oldval;
366 374
                 $index=1;
367 375
 
368
-            }
369
-            else {
376
+            } else {
370 377
 
371 378
                 $index = count($target[$key]);
372 379
 
373 380
             }
374 381
 
375
-            if ( $child != "" ) $target[$key][$index] = $child;
376
-
377
-            if ( $attributes != "" ) foreach($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue;
382
+            if ( $child != "" ) {
383
+                $target[$key][$index] = $child;
384
+            }
378 385
 
379
-            elseif ( $value != "" ) $target[$key][$index] = $value;
386
+            if ( $attributes != "" ) {
387
+                foreach($attributes as $akey => $avalue) $target[$key][$index][$akey] = $avalue;
388
+            } elseif ( $value != "" ) {
389
+                $target[$key][$index] = $value;
390
+            }
380 391
         }
381 392
 
382 393
         return $target;
@@ -393,9 +404,11 @@  discard block
 block discarded – undo
393 404
 
394 405
         foreach ($data as $key => $value) {
395 406
 
396
-            if ( is_array($value) ) $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value);
397
-
398
-            else $ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key, mb_convert_encoding($value, $this->encoding));
407
+            if ( is_array($value) ) {
408
+                $this->pushElement($ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key), $value);
409
+            } else {
410
+                $ObjectXML->addChild(is_numeric($key) ? 'KEY_'.$key : $key, mb_convert_encoding($value, $this->encoding));
411
+            }
399 412
 
400 413
         }
401 414
 
Please login to merge, or discard this patch.
src/Serialization.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
      *
38 38
      * @return  string  JSON encoded data
39 39
      */
40
-    final public function toJson($data, $flags=null) {
40
+    final public function toJson($data, $flags = null) {
41 41
 
42
-        if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for JSON serialization");
42
+        if (!(is_array($data) OR is_object($data))) throw new Exception("Invalid data for JSON serialization");
43 43
 
44 44
         return json_encode($data, $flags);
45 45
 
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return  string  XML encoded data
57 57
      */
58
-    final public function toXml($data, $prettify=false) {
58
+    final public function toXml($data, $prettify = false) {
59 59
 
60
-        if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization");
60
+        if (!(is_array($data) OR is_object($data))) throw new Exception("Invalid data for XML serialization");
61 61
 
62
-        if ( is_object($data) ) $data = $this->objectToArray($data);
62
+        if (is_object($data)) $data = $this->objectToArray($data);
63 63
 
64 64
         $xmlEngine = new XML();
65 65
         
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
      */
104 104
     final public function toYaml($data) {
105 105
 
106
-        if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization");
106
+        if (!(is_array($data) OR is_object($data))) throw new Exception("Invalid data for XML serialization");
107 107
 
108
-        if ( is_object($data) ) $data = $this->objectToArray($data);
108
+        if (is_object($data)) $data = $this->objectToArray($data);
109 109
 
110 110
         return \Spyc::YAMLDump($data);
111 111
 
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
        
148 148
         $indent = '';
149 149
 
150
-        $xmlString = str_replace("\n","",$xmlString);
150
+        $xmlString = str_replace("\n", "", $xmlString);
151 151
         $xmlString = trim(preg_replace("/<\?[^>]+>/", "", $xmlString));
152 152
         $xmlString = preg_replace("/>([\s]+)<\//", "></", $xmlString);
153 153
         $xmlString = str_replace(">", ">\n", $xmlString);
@@ -156,23 +156,23 @@  discard block
 block discarded – undo
156 156
 
157 157
         $_xmlString = '';
158 158
         
159
-        foreach($xmlStringArray as $k=>$tag){
159
+        foreach ($xmlStringArray as $k=>$tag) {
160 160
 
161 161
             if ($tag == "") continue;
162 162
             
163
-            if ($tag[0]=="<" AND $tag[1] != "/") {
163
+            if ($tag[0] == "<" AND $tag[1] != "/") {
164 164
 
165 165
                 $_xmlString .= $indent.$tag."\n";
166 166
                 $indent .= '  ';
167 167
 
168
-            } elseif($tag[0]=="<" AND $tag[1] == "/") {
168
+            } elseif ($tag[0] == "<" AND $tag[1] == "/") {
169 169
 
170
-                $indent = substr($indent,0,strlen($indent)-2);
171
-                $_xmlString .= (substr($_xmlString,strlen($_xmlString)-1)==">" || substr($_xmlString,strlen($_xmlString)-1)=="\n" ? $indent : '').$tag."\n";
170
+                $indent = substr($indent, 0, strlen($indent)-2);
171
+                $_xmlString .= (substr($_xmlString, strlen($_xmlString)-1) == ">" || substr($_xmlString, strlen($_xmlString)-1) == "\n" ? $indent : '').$tag."\n";
172 172
 
173 173
             } else {
174 174
 
175
-                $_xmlString = substr($_xmlString,0,strlen($_xmlString)-1);
175
+                $_xmlString = substr($_xmlString, 0, strlen($_xmlString)-1);
176 176
                 $_xmlString .= $tag;
177 177
 
178 178
             }
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
      */
192 192
     private function objectToArray($stdObj) {
193 193
        
194
-        if(is_object($stdObj)) {
194
+        if (is_object($stdObj)) {
195 195
 
196 196
             $array = array();
197 197
             
198
-            foreach($stdObj as $key=>$val){
198
+            foreach ($stdObj as $key=>$val) {
199 199
 
200 200
                 $array[$key] = objectToArray($val);
201 201
 
Please login to merge, or discard this patch.
Braces   +20 added lines, -8 removed lines patch added patch discarded remove patch
@@ -39,7 +39,9 @@  discard block
 block discarded – undo
39 39
      */
40 40
     final public function toJson($data, $flags=null) {
41 41
 
42
-        if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for JSON serialization");
42
+        if ( !( is_array($data) OR is_object($data) ) ) {
43
+            throw new Exception("Invalid data for JSON serialization");
44
+        }
43 45
 
44 46
         return json_encode($data, $flags);
45 47
 
@@ -57,9 +59,13 @@  discard block
 block discarded – undo
57 59
      */
58 60
     final public function toXml($data, $prettify=false) {
59 61
 
60
-        if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization");
62
+        if ( !( is_array($data) OR is_object($data) ) ) {
63
+            throw new Exception("Invalid data for XML serialization");
64
+        }
61 65
 
62
-        if ( is_object($data) ) $data = $this->objectToArray($data);
66
+        if ( is_object($data) ) {
67
+            $data = $this->objectToArray($data);
68
+        }
63 69
 
64 70
         $xmlEngine = new XML();
65 71
         
@@ -103,9 +109,13 @@  discard block
 block discarded – undo
103 109
      */
104 110
     final public function toYaml($data) {
105 111
 
106
-        if ( !( is_array($data) OR is_object($data) ) ) throw new Exception("Invalid data for XML serialization");
112
+        if ( !( is_array($data) OR is_object($data) ) ) {
113
+            throw new Exception("Invalid data for XML serialization");
114
+        }
107 115
 
108
-        if ( is_object($data) ) $data = $this->objectToArray($data);
116
+        if ( is_object($data) ) {
117
+            $data = $this->objectToArray($data);
118
+        }
109 119
 
110 120
         return \Spyc::YAMLDump($data);
111 121
 
@@ -158,7 +168,9 @@  discard block
 block discarded – undo
158 168
         
159 169
         foreach($xmlStringArray as $k=>$tag){
160 170
 
161
-            if ($tag == "") continue;
171
+            if ($tag == "") {
172
+                continue;
173
+            }
162 174
             
163 175
             if ($tag[0]=="<" AND $tag[1] != "/") {
164 176
 
@@ -203,9 +215,9 @@  discard block
 block discarded – undo
203 215
 
204 216
             return $array;
205 217
 
218
+        } else {
219
+            return $stdObj;
206 220
         }
207
-        
208
-        else return $stdObj;
209 221
 
210 222
     }
211 223
 
Please login to merge, or discard this patch.
src/ObjectRoutingTable/ObjectRoutingTable.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      *
49 49
      * @var array
50 50
      */
51
-    private $supported_route_types = array("ROUTE","REDIRECT","ERROR");
51
+    private $supported_route_types = array("ROUTE", "REDIRECT", "ERROR");
52 52
 
53 53
     /**
54 54
      * Object constructor.
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      *
78 78
      * @return  Object  $this
79 79
      */
80
-    public function setRoute($service, $type, $target, $parameters=array()) {
80
+    public function setRoute($service, $type, $target, $parameters = array()) {
81 81
 
82 82
         $this->table[$service] = array(
83 83
             "type"          =>  $type,
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function unsetRoute($service) {
100 100
 
101
-        if ( isset($this->table[$service]) ) {
101
+        if (isset($this->table[$service])) {
102 102
 
103 103
             unset($this->table[$service]);
104 104
 
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
 
122 122
         // If service is null, route to landing or (if not specified) to default route
123 123
 
124
-        if ( empty($service) ) return $this->routeToLanding();
124
+        if (empty($service)) return $this->routeToLanding();
125 125
 
126 126
         // If service is in table, check if it is routable (in case of "ROUTE" route).
127 127
         // If true, route request
128 128
         // If false, return a 500 error
129 129
 
130
-        if ( isset($this->table[$service]) ) {
130
+        if (isset($this->table[$service])) {
131 131
 
132
-            if ( $this->table[$service]["type"] == "ROUTE" ) {
132
+            if ($this->table[$service]["type"] == "ROUTE") {
133 133
 
134
-                if ( $this->routable($this->table[$service]["target"]) ) return $this->table[$service];
134
+                if ($this->routable($this->table[$service]["target"])) return $this->table[$service];
135 135
 
136 136
                 else return $this->routeToNowhere();
137 137
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         // If autoroute is enabled, try to match service name with a service file.
145 145
         // If true, try to route request
146 146
 
147
-        else if ( defined('DISPATCHER_AUTO_ROUTE') && DISPATCHER_AUTO_ROUTE === true AND $this->routable($service.".php", true) ) {
147
+        else if (defined('DISPATCHER_AUTO_ROUTE') && DISPATCHER_AUTO_ROUTE === true AND $this->routable($service.".php", true)) {
148 148
 
149 149
             return array(
150 150
                 "type"          =>  "ROUTE",
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
      *
179 179
      * @return  bool
180 180
      */
181
-    private function routable($target, $relative=false) {
181
+    private function routable($target, $relative = false) {
182 182
 
183
-        if ( $relative ) return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false;
183
+        if ($relative) return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false;
184 184
 
185 185
         else return is_readable($target) ? true : false;
186 186
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      */
194 194
     private function routeToLanding() {
195 195
 
196
-        if ( isset($this->table[""]) ) {
196
+        if (isset($this->table[""])) {
197 197
 
198 198
             return $this->table[""];
199 199
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
      */
211 211
     private function routeToDefault() {
212 212
 
213
-        if ( isset($this->table["default"]) ) {
213
+        if (isset($this->table["default"])) {
214 214
 
215 215
             return $this->table["default"];
216 216
 
Please login to merge, or discard this patch.
Braces   +22 added lines, -14 removed lines patch added patch discarded remove patch
@@ -121,7 +121,9 @@  discard block
 block discarded – undo
121 121
 
122 122
         // If service is null, route to landing or (if not specified) to default route
123 123
 
124
-        if ( empty($service) ) return $this->routeToLanding();
124
+        if ( empty($service) ) {
125
+            return $this->routeToLanding();
126
+        }
125 127
 
126 128
         // If service is in table, check if it is routable (in case of "ROUTE" route).
127 129
         // If true, route request
@@ -131,14 +133,16 @@  discard block
 block discarded – undo
131 133
 
132 134
             if ( $this->table[$service]["type"] == "ROUTE" ) {
133 135
 
134
-                if ( $this->routable($this->table[$service]["target"]) ) return $this->table[$service];
135
-
136
-                else return $this->routeToNowhere();
136
+                if ( $this->routable($this->table[$service]["target"]) ) {
137
+                    return $this->table[$service];
138
+                } else {
139
+                    return $this->routeToNowhere();
140
+                }
137 141
 
142
+            } else {
143
+                return $this->table[$service];
138 144
             }
139 145
 
140
-            else return $this->table[$service];
141
-
142 146
         }
143 147
 
144 148
         // If autoroute is enabled, try to match service name with a service file.
@@ -156,7 +160,9 @@  discard block
 block discarded – undo
156 160
 
157 161
         // If a route cannot be traced, emit a 404 - not found - response
158 162
 
159
-        else return $this->routeToNotfound();
163
+        else {
164
+            return $this->routeToNotfound();
165
+        }
160 166
 
161 167
     }
162 168
 
@@ -180,9 +186,11 @@  discard block
 block discarded – undo
180 186
      */
181 187
     private function routable($target, $relative=false) {
182 188
 
183
-        if ( $relative ) return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false;
184
-
185
-        else return is_readable($target) ? true : false;
189
+        if ( $relative ) {
190
+            return is_readable(DISPATCHER_SERVICES_FOLDER.$target) ? true : false;
191
+        } else {
192
+            return is_readable($target) ? true : false;
193
+        }
186 194
 
187 195
     }
188 196
 
@@ -197,10 +205,10 @@  discard block
 block discarded – undo
197 205
 
198 206
             return $this->table[""];
199 207
 
208
+        } else {
209
+            return $this->routeToDefault();
200 210
         }
201 211
 
202
-        else return $this->routeToDefault();
203
-
204 212
     }
205 213
 
206 214
     /**
@@ -214,10 +222,10 @@  discard block
 block discarded – undo
214 222
 
215 223
             return $this->table["default"];
216 224
 
225
+        } else {
226
+            return $this->routeToNotfound();
217 227
         }
218 228
 
219
-        else return $this->routeToNotfound();
220
-
221 229
     }
222 230
 
223 231
     /**
Please login to merge, or discard this patch.