Completed
Push — 4.0 ( b44693...cafdfc )
by Marco
02:39
created
src/Comodojo/Dispatcher/Router/Table.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
 
137 137
     public function load($routes) {
138 138
 
139
-        if ( !empty($routes) ) {
139
+        if (!empty($routes)) {
140 140
 
141
-            foreach( $routes as $name => $route ) {
141
+            foreach ($routes as $name => $route) {
142 142
 
143 143
                 $this->add($route['route'], $route['type'], $route['class'], $route['parameters']);
144 144
                 // $this->add($name, $route['type'], $route['class'], $route['parameters']);
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
 
157 157
     private function readCache() {
158 158
 
159
-        if ( $this->configuration->get('routing-table-cache') !== true ) return;
159
+        if ($this->configuration->get('routing-table-cache') !== true) return;
160 160
 
161 161
         $data = $this->cache->read();
162 162
 
163
-        if ( is_null($data) ) {
163
+        if (is_null($data)) {
164 164
 
165 165
             $this->routes = [];
166 166
 
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 
177 177
     private function dumpCache() {
178 178
 
179
-        if ( $this->configuration->get('routing-table-cache') !== true ) return;
179
+        if ($this->configuration->get('routing-table-cache') !== true) return;
180 180
 
181 181
         $ttl = $this->configuration->get('routing-table-ttl');
182 182
 
183
-        if ( $this->cache->dump($this->routes, $ttl) ) {
183
+        if ($this->cache->dump($this->routes, $ttl)) {
184 184
             $this->logger->debug("Routing table saved to cache");
185 185
         } else {
186 186
             $this->logger->warning("Cannot save routing table to cache");
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
             ->setClassName($class) // Class to be invoked
199 199
             ->setParameters($parameters); // Parameters passed via the composer.json configuration (cache, ttl, etc...)
200 200
 
201
-        $this->logger->debug("Route table - route: " . implode("/", $folders));
201
+        $this->logger->debug("Route table - route: ".implode("/", $folders));
202 202
 
203 203
         // This method generate a global regular expression which will be able to match all the URI supported by the route
204 204
         $regex = $this->parser->read($folders, $route);
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -156,7 +156,9 @@  discard block
 block discarded – undo
156 156
 
157 157
     private function readCache() {
158 158
 
159
-        if ( $this->configuration->get('routing-table-cache') !== true ) return;
159
+        if ( $this->configuration->get('routing-table-cache') !== true ) {
160
+            return;
161
+        }
160 162
 
161 163
         $data = $this->cache->read();
162 164
 
@@ -176,7 +178,9 @@  discard block
 block discarded – undo
176 178
 
177 179
     private function dumpCache() {
178 180
 
179
-        if ( $this->configuration->get('routing-table-cache') !== true ) return;
181
+        if ( $this->configuration->get('routing-table-cache') !== true ) {
182
+            return;
183
+        }
180 184
 
181 185
         $ttl = $this->configuration->get('routing-table-ttl');
182 186
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Router/Parser.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
                 return $this->read(
106 106
                     $folders,
107 107
                     $value,
108
-                    $regex.'(?:\/'.$param_regex.')'. (($param_required)?'{1}':'?')
108
+                    $regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?')
109 109
                 );
110 110
 
111 111
             } else {
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
          * If the field is required, the regular expression is completed with a '{1}' (which make it compulsory),
162 162
          * otherwise a '?' is added.
163 163
          */
164
-        return '(?P<' . $key . '>' . $string . ')' . (($field_required)?'{1}':'?');
164
+        return '(?P<'.$key.'>'.$string.')'.(($field_required) ? '{1}' : '?');
165 165
 
166 166
     }
167 167
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -96,7 +96,9 @@
 block discarded – undo
96 96
                      */
97 97
                     $param_regex .= $this->param($key, $string, $value);
98 98
 
99
-                    if ($value->isQueryRequired($key)) $param_required = true;
99
+                    if ($value->isQueryRequired($key)) {
100
+                        $param_required = true;
101
+                    }
100 102
 
101 103
                     $this->logger->debug("Route parser - parameter regex: $param_regex");
102 104
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Router/Model.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -106,23 +106,23 @@  discard block
 block discarded – undo
106 106
 
107 107
     public function route(Request $request) {
108 108
 
109
-        $method = (string) $request->getMethod();
109
+        $method = (string)$request->getMethod();
110 110
 
111 111
         $methods = $this->configuration->get('allowed-http-methods');
112 112
 
113
-        if ( !empty($methods) && in_array($method, $methods) === false ) {
113
+        if (!empty($methods) && in_array($method, $methods) === false) {
114 114
 
115 115
             throw new DispatcherException("Method not allowed", 0, null, 405, array(
116
-                "Allow" => implode(",",$methods)
116
+                "Allow" => implode(",", $methods)
117 117
             ));
118 118
 
119 119
         }
120 120
 
121 121
         $this->setRequest($request);
122 122
 
123
-        if ( $this->bypass_routing === false ) {
123
+        if ($this->bypass_routing === false) {
124 124
 
125
-            if ( !$this->parse() ) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404);
125
+            if (!$this->parse()) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404);
126 126
 
127 127
         }
128 128
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
         $class = $this->route->getClassName();
136 136
 
137
-        if ( class_exists($class) ) {
137
+        if (class_exists($class)) {
138 138
 
139 139
             // All the route parameters are also added to the query parameters
140 140
             foreach ($this->route->getRequestParameters() as $parameter => $value) {
@@ -162,13 +162,13 @@  discard block
 block discarded – undo
162 162
 
163 163
         $this->setResponse($response);
164 164
 
165
-        if ( is_null($this->route) ) {
165
+        if (is_null($this->route)) {
166 166
 
167 167
             throw new DispatcherException("Route has not been loaded!");
168 168
 
169 169
         }
170 170
 
171
-        if ( $this->bypass_service ) {
171
+        if ($this->bypass_service) {
172 172
 
173 173
             return;
174 174
 
@@ -176,15 +176,15 @@  discard block
 block discarded – undo
176 176
 
177 177
         $service = $this->getServiceInstance();
178 178
 
179
-        if ( !is_null($service) ) {
179
+        if (!is_null($service)) {
180 180
 
181 181
             $result = "";
182 182
 
183
-            $method = (string) $this->getRequest()->getMethod();
183
+            $method = (string)$this->getRequest()->getMethod();
184 184
 
185 185
             $methods = $service->getImplementedMethods();
186 186
 
187
-            if ( in_array($method, $methods) ) {
187
+            if (in_array($method, $methods)) {
188 188
 
189 189
                 $callable = $service->getMethod($method);
190 190
 
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         foreach ($this->table->getRoutes() as $regex => $value) {
228 228
 
229 229
             // The current uri is checked against all the global regular expressions associated with the routes
230
-            if ( preg_match("/" . $regex . "/", $path, $matches) ) {
230
+            if (preg_match("/".$regex."/", $path, $matches)) {
231 231
 
232 232
                 /* If a route is matched, all the bits of the route string are evalued in order to create
233 233
                  * new query parameters which will be available for the service class
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -122,7 +122,9 @@
 block discarded – undo
122 122
 
123 123
         if ( $this->bypass_routing === false ) {
124 124
 
125
-            if ( !$this->parse() ) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404);
125
+            if ( !$this->parse() ) {
126
+                throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404);
127
+            }
126 128
 
127 129
         }
128 130
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Output/Processor.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,13 +75,13 @@
 block discarded – undo
75 75
 
76 76
         $status = $response->getStatus()->get();
77 77
 
78
-        if ( !$this->codes->exists($status) ) throw new Exception("Invalid HTTP status code in response");
78
+        if (!$this->codes->exists($status)) throw new Exception("Invalid HTTP status code in response");
79 79
 
80 80
         $message = $this->codes->getMessage($status);
81 81
 
82 82
         $response->getHeaders()->send();
83 83
 
84
-        header(sprintf('HTTP/%s %s %s', (string) $request->getVersion(), $status, $message), true, $status);
84
+        header(sprintf('HTTP/%s %s %s', (string)$request->getVersion(), $status, $message), true, $status);
85 85
 
86 86
         $response->getCookies()->save();
87 87
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,9 @@
 block discarded – undo
75 75
 
76 76
         $status = $response->getStatus()->get();
77 77
 
78
-        if ( !$this->codes->exists($status) ) throw new Exception("Invalid HTTP status code in response");
78
+        if ( !$this->codes->exists($status) ) {
79
+            throw new Exception("Invalid HTTP status code in response");
80
+        }
79 81
 
80 82
         $message = $this->codes->getMessage($status);
81 83
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Response/Preprocessor/Status201.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 
31 31
         $location = $this->response->getLocation()->get();
32 32
 
33
-        if ( $location != null ) $this->response->getHeaders()->set("Location", $location);
33
+        if ($location != null) $this->response->getHeaders()->set("Location", $location);
34 34
 
35 35
         parent::consolidate();
36 36
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,9 @@
 block discarded – undo
30 30
 
31 31
         $location = $this->response->getLocation()->get();
32 32
 
33
-        if ( $location != null ) $this->response->getHeaders()->set("Location", $location);
33
+        if ( $location != null ) {
34
+            $this->response->getHeaders()->set("Location", $location);
35
+        }
34 36
 
35 37
         parent::consolidate();
36 38
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Response/Preprocessor/Status200.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
         $type = $this->response->getContent()->type();
34 34
         $charset = $this->response->getContent()->charset();
35 35
 
36
-        if ( is_null($charset) ) {
36
+        if (is_null($charset)) {
37 37
             $this->response->getHeaders()->set("Content-type", strtolower($type));
38 38
         } else {
39 39
             $this->response->getHeaders()->set("Content-type", strtolower($type)."; charset=".$charset);
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Response/Preprocessor/Status405.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
         // An Allow Header should be provided from DispatcherException
34 34
         $allow = $this->response->getHeaders()->get('Allow');
35 35
 
36
-        if ( is_null($allow) ) throw new Exception("Missing Allow header");
36
+        if (is_null($allow)) throw new Exception("Missing Allow header");
37 37
 
38 38
         parent::consolidate();
39 39
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,9 @@
 block discarded – undo
33 33
         // An Allow Header should be provided from DispatcherException
34 34
         $allow = $this->response->getHeaders()->get('Allow');
35 35
 
36
-        if ( is_null($allow) ) throw new Exception("Missing Allow header");
36
+        if ( is_null($allow) ) {
37
+            throw new Exception("Missing Allow header");
38
+        }
37 39
 
38 40
         parent::consolidate();
39 41
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Response/Preprocessor/Status301.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@
 block discarded – undo
32 32
 
33 33
         $location = $this->response->getLocation()->get();
34 34
 
35
-        if ( empty($location) ) throw new Exception("Invalid location, cannot redirect");
35
+        if (empty($location)) throw new Exception("Invalid location, cannot redirect");
36 36
 
37 37
         $this->response->getHeaders()->set("Location", $location);
38 38
 
39 39
         $content = $this->response->getContent();
40 40
 
41
-        if ( empty($content->get()) ) {
41
+        if (empty($content->get())) {
42 42
 
43 43
             $content->set(sprintf('<!DOCTYPE html>
44 44
 <html>
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,9 @@
 block discarded – undo
32 32
 
33 33
         $location = $this->response->getLocation()->get();
34 34
 
35
-        if ( empty($location) ) throw new Exception("Invalid location, cannot redirect");
35
+        if ( empty($location) ) {
36
+            throw new Exception("Invalid location, cannot redirect");
37
+        }
36 38
 
37 39
         $this->response->getHeaders()->set("Location", $location);
38 40
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Cache/ServerCache.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 
48 48
         $cache_object = $this->getCache()->setNamespace(self::$cache_namespace)->get($name);
49 49
 
50
-        if ( is_null($cache_object) ) return false;
50
+        if (is_null($cache_object)) return false;
51 51
 
52 52
         $response->import($cache_object);
53 53
 
@@ -67,15 +67,15 @@  discard block
 block discarded – undo
67 67
 
68 68
         $name = self::getCacheName($request);
69 69
 
70
-        $method = (string) $request->getMethod();
70
+        $method = (string)$request->getMethod();
71 71
 
72 72
         $status = $response->getStatus()->get();
73 73
 
74 74
         if (
75
-            ( $cache == 'SERVER' || $cache == 'BOTH' ) &&
75
+            ($cache == 'SERVER' || $cache == 'BOTH') &&
76 76
             in_array($method, self::$cachable_methods) &&
77 77
             in_array($status, self::$cachable_statuses)
78
-        ){
78
+        ) {
79 79
 
80 80
             $this->getCache()
81 81
                 ->setNamespace(self::$cache_namespace)
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 
88 88
     private static function getCacheName(Request $request) {
89 89
 
90
-        return md5( (string) $request->getMethod() . (string) $request->getUri() );
90
+        return md5((string)$request->getMethod().(string)$request->getUri());
91 91
 
92 92
     }
93 93
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,9 @@
 block discarded – undo
47 47
 
48 48
         $cache_object = $this->getCache()->setNamespace(self::$cache_namespace)->get($name);
49 49
 
50
-        if ( is_null($cache_object) ) return false;
50
+        if ( is_null($cache_object) ) {
51
+            return false;
52
+        }
51 53
 
52 54
         $response->import($cache_object);
53 55
 
Please login to merge, or discard this patch.