Completed
Push — 4.0 ( 582652...6b254d )
by Marco
02:44
created
src/Comodojo/Dispatcher/Request/Headers.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,13 +41,13 @@
 block discarded – undo
41 41
      */
42 42
     private static function getHeaders() {
43 43
 
44
-        if ( function_exists('getallheaders') ) return getallheaders();
44
+        if (function_exists('getallheaders')) return getallheaders();
45 45
 
46 46
         $headers = array();
47 47
 
48
-        foreach ( $_SERVER as $name => $value ) {
48
+        foreach ($_SERVER as $name => $value) {
49 49
 
50
-            if ( substr($name, 0, 5) == 'HTTP_' ) {
50
+            if (substr($name, 0, 5) == 'HTTP_') {
51 51
 
52 52
                 $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
53 53
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,9 @@
 block discarded – undo
41 41
      */
42 42
     private static function getHeaders() {
43 43
 
44
-        if ( function_exists('getallheaders') ) return getallheaders();
44
+        if ( function_exists('getallheaders') ) {
45
+            return getallheaders();
46
+        }
45 47
 
46 48
         $headers = array();
47 49
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Request/Post.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
 
47 47
     private static function getParameters() {
48 48
 
49
-        switch( $_SERVER['REQUEST_METHOD'] ) {
49
+        switch ($_SERVER['REQUEST_METHOD']) {
50 50
 
51 51
             case 'POST':
52 52
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Components/DefaultConfiguration.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,11 +48,11 @@
 block discarded – undo
48 48
 
49 49
     private static function urlGetAbsolute() {
50 50
 
51
-        $http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://';
51
+        $http = 'http'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://';
52 52
 
53 53
         $uri = self::uriGetAbsolute();
54 54
 
55
-        return ( $http . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost') . $uri . "/" );
55
+        return ($http.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost').$uri."/");
56 56
 
57 57
     }
58 58
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Response/Status.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
     public function set($code) {
50 50
 
51
-        if ( !$this->codes->exists($code) ) {
51
+        if (!$this->codes->exists($code)) {
52 52
 
53 53
             throw new Exception("Invalid HTTP Status Code $code");
54 54
 
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
 
61 61
     }
62 62
 
63
-    public function description($code=null) {
63
+    public function description($code = null) {
64 64
 
65
-        if ( is_null($code) ) return $this->codes->getMessage($this->status_code);
65
+        if (is_null($code)) return $this->codes->getMessage($this->status_code);
66 66
         
67 67
         return $this->codes->getMessage($code);
68 68
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,9 @@
 block discarded – undo
62 62
 
63 63
     public function description($code=null) {
64 64
 
65
-        if ( is_null($code) ) return $this->codes->getMessage($this->status_code);
65
+        if ( is_null($code) ) {
66
+            return $this->codes->getMessage($this->status_code);
67
+        }
66 68
         
67 69
         return $this->codes->getMessage($code);
68 70
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Components/HttpStatusCodes.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
 
103 103
     public function getMessage($code) {
104 104
 
105
-        if ( $this->exists($code) ) return $this->codes[$code];
105
+        if ($this->exists($code)) return $this->codes[$code];
106 106
 
107 107
         throw new Exception("Invalid HTTP status code $code");
108 108
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,9 @@
 block discarded – undo
102 102
 
103 103
     public function getMessage($code) {
104 104
 
105
-        if ( $this->exists($code) ) return $this->codes[$code];
105
+        if ( $this->exists($code) ) {
106
+            return $this->codes[$code];
107
+        }
106 108
 
107 109
         throw new Exception("Invalid HTTP status code $code");
108 110
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Request/File.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -44,6 +44,9 @@
 block discarded – undo
44 44
 
45 45
     }
46 46
 
47
+    /**
48
+     * @return string
49
+     */
47 50
     public function getTemporaryName() {
48 51
 
49 52
         return $this->tname;
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 
109 109
         if (!empty($this->path) && file_exists($this->path)) {
110 110
 
111
-            $local_name = "$this->path/" . ($as_slug ? $this->getSlug() : $this->getFileName());
111
+            $local_name = "$this->path/".($as_slug ? $this->getSlug() : $this->getFileName());
112 112
 
113
-            if ( file_exists($local_name) ) {
113
+            if (file_exists($local_name)) {
114 114
 
115 115
                 $files = glob("$local_name*");
116 116
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
             }
122 122
 
123
-            if ( move_uploaded_file($this->getTemporaryName(), $local_name) ) {
123
+            if (move_uploaded_file($this->getTemporaryName(), $local_name)) {
124 124
 
125 125
                 // return file_exists($local_name);
126 126
                 return true;
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,9 @@
 block discarded – undo
84 84
 
85 85
         $file = $this->getTemporaryName();
86 86
 
87
-        if (file_exists($file)) return file_get_contents($file);
87
+        if (file_exists($file)) {
88
+            return file_get_contents($file);
89
+        }
88 90
 
89 91
         throw new Exception("File does not exists");
90 92
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Events/DispatcherEvent.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
 
30 30
     protected $dispatcher;
31 31
 
32
-    public function __construct( Dispatcher $dispatcher ) {
32
+    public function __construct(Dispatcher $dispatcher) {
33 33
 
34 34
         parent::__construct('dispatcher');
35 35
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Dispatcher.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -207,6 +207,9 @@
 block discarded – undo
207 207
 
208 208
     }
209 209
 
210
+    /**
211
+     * @param string $name
212
+     */
210 213
     private function createServiceSpecializedEvents($name) {
211 214
 
212 215
         $this->logger->debug("Emitting $name service-event");
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
         // init core components
80 80
         // create new configuration object and merge configuration
81
-        $configuration_object = new Configuration( DefaultConfiguration::get() );
81
+        $configuration_object = new Configuration(DefaultConfiguration::get());
82 82
         $configuration_object->merge($configuration);
83 83
 
84 84
         $logger = is_null($logger) ? LogManager::createFromConfiguration($configuration_object)->getLogger() : $logger;
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 
103 103
         } catch (Exception $e) {
104 104
 
105
-            $this->logger->critical($e->getMessage(),$e->getTrace());
105
+            $this->logger->critical($e->getMessage(), $e->getTrace());
106 106
 
107 107
             throw $e;
108 108
 
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
         $logger->debug("Starting to dispatch.");
123 123
 
124 124
         $logger->debug("Emitting global dispatcher event.");
125
-        $events->emit( new DispatcherEvent($this) );
125
+        $events->emit(new DispatcherEvent($this));
126 126
 
127
-        if ( $configuration->get('enabled') === false ) {
127
+        if ($configuration->get('enabled') === false) {
128 128
 
129 129
             $logger->debug("Dispatcher disabled, shutting down gracefully.");
130 130
 
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
 
141 141
         $cache = new ServerCache($this->getCache());
142 142
 
143
-        $events->emit( $this->createServiceSpecializedEvents('dispatcher.request') );
144
-        $events->emit( $this->createServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get()) );
145
-        $events->emit( $this->createServiceSpecializedEvents('dispatcher.request.#') );
143
+        $events->emit($this->createServiceSpecializedEvents('dispatcher.request'));
144
+        $events->emit($this->createServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get()));
145
+        $events->emit($this->createServiceSpecializedEvents('dispatcher.request.#'));
146 146
 
147
-        if ( $cache->read($this->request, $this->response) ) {
147
+        if ($cache->read($this->request, $this->response)) {
148 148
             // we have a cache!
149 149
             // shutdown immediately
150 150
             return $this->shutdown();
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
 
171 171
         $logger->debug("Route acquired, type $route_type directed to $route_service");
172 172
 
173
-        $events->emit( $this->createServiceSpecializedEvents('dispatcher.route') );
174
-        $events->emit( $this->createServiceSpecializedEvents('dispatcher.route.'.$route_type) );
175
-        $events->emit( $this->createServiceSpecializedEvents('dispatcher.route.'.$route_service) );
176
-        $events->emit( $this->createServiceSpecializedEvents('dispatcher.route.#') );
173
+        $events->emit($this->createServiceSpecializedEvents('dispatcher.route'));
174
+        $events->emit($this->createServiceSpecializedEvents('dispatcher.route.'.$route_type));
175
+        $events->emit($this->createServiceSpecializedEvents('dispatcher.route.'.$route_service));
176
+        $events->emit($this->createServiceSpecializedEvents('dispatcher.route.#'));
177 177
 
178 178
         // translate route to service
179 179
         $logger->debug("Running $route_service service");
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
 
202 202
         $params = $route->getParameter('headers');
203 203
 
204
-        if ( !empty($params) && is_array($params) ) {
205
-            foreach($params as $name => $value) $this->getResponse()->getHeaders()->set($name, $value);
204
+        if (!empty($params) && is_array($params)) {
205
+            foreach ($params as $name => $value) $this->getResponse()->getHeaders()->set($name, $value);
206 206
         }
207 207
 
208 208
     }
@@ -247,9 +247,9 @@  discard block
 block discarded – undo
247 247
 
248 248
         $response->consolidate($request, $this->route);
249 249
 
250
-        $events->emit( $this->createServiceSpecializedEvents('dispatcher.response') );
251
-        $events->emit( $this->createServiceSpecializedEvents('dispatcher.response.' . $response->getStatus()->get()) );
252
-        $events->emit( $this->createServiceSpecializedEvents('dispatcher.response.#') );
250
+        $events->emit($this->createServiceSpecializedEvents('dispatcher.response'));
251
+        $events->emit($this->createServiceSpecializedEvents('dispatcher.response.'.$response->getStatus()->get()));
252
+        $events->emit($this->createServiceSpecializedEvents('dispatcher.response.#'));
253 253
 
254 254
         $this->logger->debug("Composing return value");
255 255
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -202,7 +202,9 @@
 block discarded – undo
202 202
         $params = $route->getParameter('headers');
203 203
 
204 204
         if ( !empty($params) && is_array($params) ) {
205
-            foreach($params as $name => $value) $this->getResponse()->getHeaders()->set($name, $value);
205
+            foreach($params as $name => $value) {
206
+                $this->getResponse()->getHeaders()->set($name, $value);
207
+            }
206 208
         }
207 209
 
208 210
     }
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Response/Model.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -95,6 +95,9 @@
 block discarded – undo
95 95
 
96 96
     }
97 97
 
98
+    /**
99
+     * @return string
100
+     */
98 101
     public function getContent() {
99 102
 
100 103
         return $this->content;
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
     use TimingTrait;
37 37
 
38
-    protected static $no_content_statuses = [100,101,102,204,304];
38
+    protected static $no_content_statuses = [100, 101, 102, 204, 304];
39 39
 
40 40
     protected static $cacheable_methods = ['GET', 'HEAD', 'POST', 'PUT'];
41 41
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 
138 138
     public function export() {
139 139
 
140
-        return (object) [
140
+        return (object)[
141 141
             'headers' => $this->getHeaders(),
142 142
             'cookies' => $this->getCookies()->getAll(),
143 143
             'status' => $this->getStatus(),
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
 
150 150
     public function import($data) {
151 151
 
152
-        if ( isset($data->headers) ) $this->setHeaders($data->headers);
153
-        if ( isset($data->status) ) $this->setStatus($data->status);
154
-        if ( isset($data->content) ) $this->setContent($data->content);
155
-        if ( isset($data->location) ) $this->setLocation($data->location);
152
+        if (isset($data->headers)) $this->setHeaders($data->headers);
153
+        if (isset($data->status)) $this->setStatus($data->status);
154
+        if (isset($data->content)) $this->setContent($data->content);
155
+        if (isset($data->location)) $this->setLocation($data->location);
156 156
 
157
-        if ( isset($data->cookies) && is_array($data->cookies) ) {
157
+        if (isset($data->cookies) && is_array($data->cookies)) {
158 158
             $cookies = $this->getCookies();
159 159
             foreach ($data->cookies as $name => $cookie) $cookies->add($cookie);
160 160
         }
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         $output_class_name = "\\Comodojo\\Dispatcher\\Response\\Preprocessor\\Status".$status;
169 169
 
170 170
         // @TODO: this condition will be removed when all preprocessors ready
171
-        if ( class_exists($output_class_name) ) {
171
+        if (class_exists($output_class_name)) {
172 172
             $output = new $output_class_name($this);
173 173
         } else {
174 174
             $output = new \Comodojo\Dispatcher\Response\Preprocessor\Status200($this);
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 
177 177
         $output->consolidate();
178 178
 
179
-        if ( $route != null ) {
179
+        if ($route != null) {
180 180
             $this->setClientCache($request, $route);
181 181
         }
182 182
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         $content = $this->getContent();
185 185
         $headers = $this->getHeaders();
186 186
 
187
-        if ( (string) $request->getMethod() == 'HEAD' && !in_array($status, self::$no_content_statuses) ) {
187
+        if ((string)$request->getMethod() == 'HEAD' && !in_array($status, self::$no_content_statuses)) {
188 188
             $length = $content->length();
189 189
             $content->set(null);
190 190
             if ($length) $headers->set('Content-Length', $length);
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
             $headers->delete('Content-Length');
195 195
         }
196 196
 
197
-        if ( (string) $request->getVersion() == '1.0' && false !== strpos($headers->get('Cache-Control'), 'no-cache')) {
197
+        if ((string)$request->getVersion() == '1.0' && false !== strpos($headers->get('Cache-Control'), 'no-cache')) {
198 198
             $headers->set('pragma', 'no-cache');
199 199
             $headers->set('expires', -1);
200 200
         }
@@ -204,20 +204,20 @@  discard block
 block discarded – undo
204 204
     private function setClientCache(Request $request, Route $route) {
205 205
 
206 206
         $cache = strtoupper($route->getParameter('cache'));
207
-        $ttl = (int) $route->getParameter('ttl');
207
+        $ttl = (int)$route->getParameter('ttl');
208 208
 
209 209
         if (
210 210
             ($cache == 'CLIENT' || $cache == 'BOTH') &&
211
-            in_array((string) $request->getMethod(), self::$cacheable_methods) &&
211
+            in_array((string)$request->getMethod(), self::$cacheable_methods) &&
212 212
             in_array($this->getStatus()->get(), self::$cacheable_statuses)
213 213
             // @TODO: here we should also check for Cache-Control no-store or private;
214 214
             //        the cache layer will be improoved in future versions.
215 215
         ) {
216 216
 
217 217
             $headers = $this->getHeaders();
218
-            $timestamp = (int) $this->getTime()->format('U') + $ttl;
218
+            $timestamp = (int)$this->getTime()->format('U')+$ttl;
219 219
 
220
-            if ( $ttl > 0 ) {
220
+            if ($ttl > 0) {
221 221
 
222 222
                 $headers->set("Cache-Control", "max-age=".$ttl.", must-revalidate");
223 223
                 $headers->set("Expires", gmdate("D, d M Y H:i:s", $timestamp)." GMT");
Please login to merge, or discard this patch.
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -149,14 +149,24 @@  discard block
 block discarded – undo
149 149
 
150 150
     public function import($data) {
151 151
 
152
-        if ( isset($data->headers) ) $this->setHeaders($data->headers);
153
-        if ( isset($data->status) ) $this->setStatus($data->status);
154
-        if ( isset($data->content) ) $this->setContent($data->content);
155
-        if ( isset($data->location) ) $this->setLocation($data->location);
152
+        if ( isset($data->headers) ) {
153
+            $this->setHeaders($data->headers);
154
+        }
155
+        if ( isset($data->status) ) {
156
+            $this->setStatus($data->status);
157
+        }
158
+        if ( isset($data->content) ) {
159
+            $this->setContent($data->content);
160
+        }
161
+        if ( isset($data->location) ) {
162
+            $this->setLocation($data->location);
163
+        }
156 164
 
157 165
         if ( isset($data->cookies) && is_array($data->cookies) ) {
158 166
             $cookies = $this->getCookies();
159
-            foreach ($data->cookies as $name => $cookie) $cookies->add($cookie);
167
+            foreach ($data->cookies as $name => $cookie) {
168
+                $cookies->add($cookie);
169
+            }
160 170
         }
161 171
 
162 172
     }
@@ -187,7 +197,9 @@  discard block
 block discarded – undo
187 197
         if ( (string) $request->getMethod() == 'HEAD' && !in_array($status, self::$no_content_statuses) ) {
188 198
             $length = $content->length();
189 199
             $content->set(null);
190
-            if ($length) $headers->set('Content-Length', $length);
200
+            if ($length) {
201
+                $headers->set('Content-Length', $length);
202
+            }
191 203
         }
192 204
 
193 205
         if ($headers->get('Transfer-Encoding') != null) {
Please login to merge, or discard this patch.