Completed
Push — 4.0 ( 37a570...937edb )
by Marco
12:16
created
src/Comodojo/Dispatcher/Dispatcher.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -167,6 +167,9 @@
 block discarded – undo
167 167
 
168 168
     }
169 169
 
170
+    /**
171
+     * @param string $name
172
+     */
170 173
     private function emitServiceSpecializedEvents($name) {
171 174
 
172 175
         return new ServiceEvent(
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -192,7 +192,9 @@
 block discarded – undo
192 192
 
193 193
         if ( !empty($params) && is_array($params) ) {
194 194
 
195
-            foreach($params as $name=>$value) $this->response->headers->set($name, $value);
195
+            foreach($params as $name=>$value) {
196
+                $this->response->headers->set($name, $value);
197
+            }
196 198
         }
197 199
 
198 200
     }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 
75 75
         // init core components
76 76
         // create new configuration object and merge configuration
77
-        $configuration_object = new Configuration( DefaultConfiguration::get() );
77
+        $configuration_object = new Configuration(DefaultConfiguration::get());
78 78
         $configuration_object->merge($configuration);
79 79
         $logger = is_null($logger) ? LogManager::createFromConfiguration($configuration_object)->getLogger() : $logger;
80 80
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             $this->setRaw('response', new Response($this->configuration, $this->logger));
96 96
 
97 97
         } catch (Exception $e) {
98
-            $this->logger->critical($e->getMessage(),$e->getTrace());
98
+            $this->logger->critical($e->getMessage(), $e->getTrace());
99 99
             throw $e;
100 100
         }
101 101
 
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
 
111 111
         $this->logger->debug("Emitting global dispatcher event.");
112 112
 
113
-        $this->events->emit( new DispatcherEvent($this) );
113
+        $this->events->emit(new DispatcherEvent($this));
114 114
 
115
-        if ( $this->configuration->get('enabled') === false ) {
115
+        if ($this->configuration->get('enabled') === false) {
116 116
 
117 117
             $this->logger->debug("Dispatcher disabled, shutting down gracefully.");
118 118
 
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
 
131 131
         $cache = new ServerCache($this->cache);
132 132
 
133
-        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request') );
133
+        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request'));
134 134
 
135
-        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get()) );
135
+        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.'.$this->request->method->get()));
136 136
 
137
-        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.request.#') );
137
+        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.request.#'));
138 138
 
139
-        if ( $cache->read($this->request, $this->response) ) {
139
+        if ($cache->read($this->request, $this->response)) {
140 140
 
141 141
             return $this->shutdown();
142 142
 
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
 
165 165
         $this->logger->debug("Route acquired, type $route_type directed to $route_service");
166 166
 
167
-        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route') );
167
+        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route'));
168 168
 
169
-        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type) );
169
+        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_type));
170 170
 
171
-        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service) );
171
+        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.'.$route_service));
172 172
 
173
-        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.route.#') );
173
+        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.route.#'));
174 174
 
175 175
         // translate route to service
176 176
 
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
 
201 201
         $params = $route->getParameter('headers');
202 202
 
203
-        if ( !empty($params) && is_array($params) ) {
203
+        if (!empty($params) && is_array($params)) {
204 204
 
205
-            foreach($params as $name=>$value) $this->response->headers->set($name, $value);
205
+            foreach ($params as $name=>$value) $this->response->headers->set($name, $value);
206 206
         }
207 207
 
208 208
     }
@@ -242,11 +242,11 @@  discard block
 block discarded – undo
242 242
 
243 243
         $this->response->consolidate($this->request, $this->route);
244 244
 
245
-        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response') );
245
+        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response'));
246 246
 
247
-        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get()) );
247
+        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.'.$this->response->status->get()));
248 248
 
249
-        $this->events->emit( $this->emitServiceSpecializedEvents('dispatcher.response.#') );
249
+        $this->events->emit($this->emitServiceSpecializedEvents('dispatcher.response.#'));
250 250
 
251 251
         $this->logger->debug("Composing return value");
252 252
 
Please login to merge, or discard this patch.
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/Request/Query.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/Router/Parser.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
                  */
74 74
                 foreach ($decoded as $key => $string) {
75 75
 
76
-                    $this->logger->debug("PARAMETER KEY: " . $key);
76
+                    $this->logger->debug("PARAMETER KEY: ".$key);
77 77
 
78
-                    $this->logger->debug("PARAMETER STRING: " . $string);
78
+                    $this->logger->debug("PARAMETER STRING: ".$string);
79 79
                     
80 80
                     /* The key and the regex of every paramater is passed to the 'param'
81 81
                      * method which will build an appropriate regular expression and will understand 
@@ -83,14 +83,14 @@  discard block
 block discarded – undo
83 83
                      */
84 84
                     $param_regex .= $this->param($key, $string, $param_required, $value);
85 85
 
86
-                    $this->logger->debug("PARAMETER REGEX: " . $param_regex);
86
+                    $this->logger->debug("PARAMETER REGEX: ".$param_regex);
87 87
 
88 88
                 }
89 89
                 // Once the parameter is analyzed, the result is passed to the next iteration
90 90
                 return $this->read(
91 91
                     $folders,
92 92
                     $value,
93
-                    $regex.'(?:\/'.$param_regex.')'. (($param_required)?'{1}':'?')
93
+                    $regex.'(?:\/'.$param_regex.')'.(($param_required) ? '{1}' : '?')
94 94
                 );
95 95
 
96 96
             } else {
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
          * If the field is required, the regular expression is completed with a '{1}' (which make it compulsory),
156 156
          * otherwise a '?' is added.
157 157
          */
158
-        return '(?P<' . $key . '>' . $string . ')' . (($field_required)?'{1}':'?');
158
+        return '(?P<'.$key.'>'.$string.')'.(($field_required) ? '{1}' : '?');
159 159
 
160 160
     }
161 161
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -103,7 +103,9 @@
 block discarded – undo
103 103
                      */
104 104
                     $param_regex .= $this->param($key, $string, $value);
105 105
                     
106
-                    if ($value->isQueryRequired($key)) $param_required = true;
106
+                    if ($value->isQueryRequired($key)) {
107
+                        $param_required = true;
108
+                    }
107 109
 
108 110
                     $this->logger->debug("PARAMETER REGEX: " . $param_regex);
109 111
 
Please login to merge, or discard this patch.
src/Comodojo/Dispatcher/Router/Model.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
 
109 109
         $methods = $this->configuration->get('allowed-http-methods');
110 110
 
111
-        if ( ( $methods != null || !empty($methods) ) && in_array($method, $methods) === false ) {
111
+        if (($methods != null || !empty($methods)) && in_array($method, $methods) === false) {
112 112
 
113 113
             throw new DispatcherException("Method not allowed", 0, null, 405, array(
114
-                "Allow" => implode(",",$methods)
114
+                "Allow" => implode(",", $methods)
115 115
             ));
116 116
 
117 117
         }
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
             
139 139
         }
140 140
         
141
-        if ( $this->bypass_service ) {
141
+        if ($this->bypass_service) {
142 142
             
143 143
             return;
144 144
             
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
             $methods = $service->getImplementedMethods();
160 160
 
161
-            if ( in_array($method, $methods) ) {
161
+            if (in_array($method, $methods)) {
162 162
 
163 163
                 $callable = $service->getMethod($method);
164 164
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
         foreach ($this->table->routes() as $regex => $value) {
202 202
             
203 203
             // The current uri is checked against all the global regular expressions associated with the routes
204
-            if (preg_match("/" . $regex . "/", $path, $matches)) {
204
+            if (preg_match("/".$regex."/", $path, $matches)) {
205 205
 
206 206
                 /* If a route is matched, all the bits of the route string are evalued in order to create
207 207
                  * new query parameters which will be available for the service class
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -105,7 +105,9 @@  discard block
 block discarded – undo
105 105
 
106 106
         if (!$this->bypass_routing) {
107 107
 
108
-            if (!$this->parse()) throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404);
108
+            if (!$this->parse()) {
109
+                throw new DispatcherException("Unable to find a valid route for the specified uri", 0, null, 404);
110
+            }
109 111
 
110 112
         }
111 113
 
@@ -133,8 +135,9 @@  discard block
 block discarded – undo
133 135
                 $this->extra
134 136
             );
135 137
 
138
+        } else {
139
+            return null;
136 140
         }
137
-        else return null;
138 141
         
139 142
     }
140 143
 
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/Preprocessor/Status301.php 2 patches
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()->location()->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()->headers()->set("Location: ".$location);
38 40
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@
 block discarded – undo
32 32
 
33 33
         $location = $this->response->location->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->headers->set("Location: ".$location);
38 38
 
39
-        if ( empty($this->response->content->get()) ) {
39
+        if (empty($this->response->content->get())) {
40 40
 
41 41
             $this->response->content->set(sprintf('<!DOCTYPE html>
42 42
 <html>
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()->headers()->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()->headers()->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.