@@ -85,8 +85,10 @@ |
||
| 85 | 85 | if ($characterDeficit == 0) { |
| 86 | 86 | //If the word is full and we're not short any characters, ignore the character |
| 87 | 87 | continue; |
| 88 | - }else |
|
| 89 | - $characterDeficit--; //If we are short some characters, decrement the defecit and carry on with adding the character to the abbreviation |
|
| 88 | + } else { |
|
| 89 | + $characterDeficit--; |
|
| 90 | + } |
|
| 91 | + //If we are short some characters, decrement the defecit and carry on with adding the character to the abbreviation |
|
| 90 | 92 | } |
| 91 | 93 | $abbreviation .= $currentChar; //Add the character to the abbreviation |
| 92 | 94 | $abbrevLength++; //Increment abbreviation length |
@@ -112,7 +112,7 @@ |
||
| 112 | 112 | |
| 113 | 113 | $this->explode = explode('.', $this->name); |
| 114 | 114 | } |
| 115 | - }else { |
|
| 115 | + } else { |
|
| 116 | 116 | $this->name = $_FILES[$filename]['name']; |
| 117 | 117 | $this->size = $_FILES[$filename]['size']; |
| 118 | 118 | $this->type = $_FILES[$filename]['type']; |
@@ -54,8 +54,9 @@ discard block |
||
| 54 | 54 | private function style_changed() |
| 55 | 55 | { |
| 56 | 56 | foreach ($this->filenames as $filename) { |
| 57 | - if (!is_file($this->get_cache_name($filename))) |
|
| 58 | - return true; |
|
| 57 | + if (!is_file($this->get_cache_name($filename))) { |
|
| 58 | + return true; |
|
| 59 | + } |
|
| 59 | 60 | } |
| 60 | 61 | return false; |
| 61 | 62 | } |
@@ -88,8 +89,9 @@ discard block |
||
| 88 | 89 | |
| 89 | 90 | // remove any old, lingering caches for this file |
| 90 | 91 | if ($dead_files = glob($this->get_cache_name($filename , TRUE) , GLOB_NOESCAPE)) { |
| 91 | - foreach ($dead_files as $dead_file) |
|
| 92 | - unlink($dead_file); |
|
| 92 | + foreach ($dead_files as $dead_file) { |
|
| 93 | + unlink($dead_file); |
|
| 94 | + } |
|
| 93 | 95 | } |
| 94 | 96 | |
| 95 | 97 | $compressed = $this->compress(file_get_contents($filename)); |
@@ -43,9 +43,10 @@ discard block |
||
| 43 | 43 | ]; |
| 44 | 44 | |
| 45 | 45 | $this->options = array_merge($default_options, $options); |
| 46 | - if(array_key_exists('decoders', $options)) |
|
| 47 | - $this->options['decoders'] = array_merge( |
|
| 46 | + if(array_key_exists('decoders', $options)) { |
|
| 47 | + $this->options['decoders'] = array_merge( |
|
| 48 | 48 | $default_options['decoders'], $options['decoders']); |
| 49 | + } |
|
| 49 | 50 | } |
| 50 | 51 | |
| 51 | 52 | public function set_option($key, $value){ |
@@ -90,8 +91,9 @@ discard block |
||
| 90 | 91 | |
| 91 | 92 | public function offsetGet($key){ |
| 92 | 93 | $this->decode_response(); |
| 93 | - if(!$this->offsetExists($key)) |
|
| 94 | - return NULL; |
|
| 94 | + if(!$this->offsetExists($key)) { |
|
| 95 | + return NULL; |
|
| 96 | + } |
|
| 95 | 97 | |
| 96 | 98 | return is_array($this->decoded_response)? |
| 97 | 99 | $this->decoded_response[$key] : $this->decoded_response->{$key}; |
@@ -140,9 +142,10 @@ discard block |
||
| 140 | 142 | CURLOPT_USERAGENT => $client->options['user_agent'] |
| 141 | 143 | ]; |
| 142 | 144 | |
| 143 | - if($client->options['username'] && $client->options['password']) |
|
| 144 | - $curlopt[CURLOPT_USERPWD] = sprintf("%s:%s", |
|
| 145 | + if($client->options['username'] && $client->options['password']) { |
|
| 146 | + $curlopt[CURLOPT_USERPWD] = sprintf("%s:%s", |
|
| 145 | 147 | $client->options['username'], $client->options['password']); |
| 148 | + } |
|
| 146 | 149 | |
| 147 | 150 | if(count($client->options['headers']) || count($headers)){ |
| 148 | 151 | $curlopt[CURLOPT_HTTPHEADER] = []; |
@@ -154,8 +157,9 @@ discard block |
||
| 154 | 157 | } |
| 155 | 158 | } |
| 156 | 159 | |
| 157 | - if($client->options['format']) |
|
| 158 | - $client->url .= '.'.$client->options['format']; |
|
| 160 | + if($client->options['format']) { |
|
| 161 | + $client->url .= '.'.$client->options['format']; |
|
| 162 | + } |
|
| 159 | 163 | |
| 160 | 164 | // Allow passing parameters as a pre-encoded string (or something that |
| 161 | 165 | // allows casting to a string). Parameters passed as strings will not be |
@@ -167,32 +171,31 @@ discard block |
||
| 167 | 171 | // http_build_query automatically adds an array index to repeated |
| 168 | 172 | // parameters which is not desirable on most systems. This hack |
| 169 | 173 | // reverts "key[0]=foo&key[1]=bar" to "key[]=foo&key[]=bar" |
| 170 | - if(!$client->options['build_indexed_queries']) |
|
| 171 | - $parameters_string = preg_replace( |
|
| 174 | + if(!$client->options['build_indexed_queries']) { |
|
| 175 | + $parameters_string = preg_replace( |
|
| 172 | 176 | "/%5B[0-9]+%5D=/simU", "%5B%5D=", $parameters_string); |
| 177 | + } |
|
| 178 | + } else { |
|
| 179 | + $parameters_string = (string) $parameters; |
|
| 173 | 180 | } |
| 174 | - else |
|
| 175 | - $parameters_string = (string) $parameters; |
|
| 176 | 181 | |
| 177 | 182 | if(strtoupper($method) == 'POST'){ |
| 178 | 183 | $curlopt[CURLOPT_POST] = TRUE; |
| 179 | 184 | $curlopt[CURLOPT_POSTFIELDS] = $parameters_string; |
| 180 | - } |
|
| 181 | - elseif(strtoupper($method) == 'HEAD'){ |
|
| 185 | + } elseif(strtoupper($method) == 'HEAD'){ |
|
| 182 | 186 | $curlopt[CURLOPT_NOBODY] = TRUE; |
| 183 | - } |
|
| 184 | - elseif(strtoupper($method) != 'GET'){ |
|
| 187 | + } elseif(strtoupper($method) != 'GET'){ |
|
| 185 | 188 | $curlopt[CURLOPT_CUSTOMREQUEST] = strtoupper($method); |
| 186 | 189 | $curlopt[CURLOPT_POSTFIELDS] = $parameters_string; |
| 187 | - } |
|
| 188 | - elseif($parameters_string){ |
|
| 190 | + } elseif($parameters_string){ |
|
| 189 | 191 | $client->url .= strpos($client->url, '?')? '&' : '?'; |
| 190 | 192 | $client->url .= $parameters_string; |
| 191 | 193 | } |
| 192 | 194 | |
| 193 | 195 | if($client->options['base_url']){ |
| 194 | - if($client->url[0] != '/' && substr($client->options['base_url'], -1) != '/') |
|
| 195 | - $client->url = '/' . $client->url; |
|
| 196 | + if($client->url[0] != '/' && substr($client->options['base_url'], -1) != '/') { |
|
| 197 | + $client->url = '/' . $client->url; |
|
| 198 | + } |
|
| 196 | 199 | $client->url = $client->options['base_url'] . $client->url; |
| 197 | 200 | } |
| 198 | 201 | $curlopt[CURLOPT_URL] = $client->url; |
@@ -220,24 +223,26 @@ discard block |
||
| 220 | 223 | do { |
| 221 | 224 | if(strlen(trim($line)) == 0){ |
| 222 | 225 | // Since we tokenize on \n, use the remaining \r to detect empty lines. |
| 223 | - if(count($headers) > 0) break; // Must be the newline after headers, move on to response body |
|
| 224 | - } |
|
| 225 | - elseif(strpos($line, 'HTTP') === 0){ |
|
| 226 | + if(count($headers) > 0) { |
|
| 227 | + break; |
|
| 228 | + } |
|
| 229 | + // Must be the newline after headers, move on to response body |
|
| 230 | + } elseif(strpos($line, 'HTTP') === 0){ |
|
| 226 | 231 | // One or more HTTP status lines |
| 227 | 232 | $this->response_status_lines[] = trim($line); |
| 228 | - } |
|
| 229 | - else { |
|
| 233 | + } else { |
|
| 230 | 234 | // Has to be a header |
| 231 | 235 | list($key, $value) = explode(':', $line, 2); |
| 232 | 236 | $key = trim(strtolower(str_replace('-', '_', $key))); |
| 233 | 237 | $value = trim($value); |
| 234 | 238 | |
| 235 | - if(empty($headers[$key])) |
|
| 236 | - $headers[$key] = $value; |
|
| 237 | - elseif(is_array($headers[$key])) |
|
| 238 | - $headers[$key][] = $value; |
|
| 239 | - else |
|
| 240 | - $headers[$key] = [$headers[$key], $value]; |
|
| 239 | + if(empty($headers[$key])) { |
|
| 240 | + $headers[$key] = $value; |
|
| 241 | + } elseif(is_array($headers[$key])) { |
|
| 242 | + $headers[$key][] = $value; |
|
| 243 | + } else { |
|
| 244 | + $headers[$key] = [$headers[$key], $value]; |
|
| 245 | + } |
|
| 241 | 246 | } |
| 242 | 247 | } while($line = strtok("\n")); |
| 243 | 248 | |
@@ -246,18 +251,21 @@ discard block |
||
| 246 | 251 | } |
| 247 | 252 | |
| 248 | 253 | public function get_response_format(){ |
| 249 | - if(!$this->response) |
|
| 250 | - throw new RestClientException( |
|
| 254 | + if(!$this->response) { |
|
| 255 | + throw new RestClientException( |
|
| 251 | 256 | "A response must exist before it can be decoded."); |
| 257 | + } |
|
| 252 | 258 | |
| 253 | 259 | // User-defined format. |
| 254 | - if(!empty($this->options['format'])) |
|
| 255 | - return $this->options['format']; |
|
| 260 | + if(!empty($this->options['format'])) { |
|
| 261 | + return $this->options['format']; |
|
| 262 | + } |
|
| 256 | 263 | |
| 257 | 264 | // Extract format from response content-type header. |
| 258 | - if(!empty($this->headers->content_type)) |
|
| 259 | - if(preg_match($this->options['format_regex'], $this->headers->content_type, $matches)) |
|
| 265 | + if(!empty($this->headers->content_type)) { |
|
| 266 | + if(preg_match($this->options['format_regex'], $this->headers->content_type, $matches)) |
|
| 260 | 267 | return $matches[2]; |
| 268 | + } |
|
| 261 | 269 | |
| 262 | 270 | throw new RestClientException( |
| 263 | 271 | "Response format could not be determined."); |
@@ -266,9 +274,10 @@ discard block |
||
| 266 | 274 | public function decode_response(){ |
| 267 | 275 | if(empty($this->decoded_response)){ |
| 268 | 276 | $format = $this->get_response_format(); |
| 269 | - if(!array_key_exists($format, $this->options['decoders'])) |
|
| 270 | - throw new RestClientException("'${format}' is not a supported ". |
|
| 277 | + if(!array_key_exists($format, $this->options['decoders'])) { |
|
| 278 | + throw new RestClientException("'${format}' is not a supported ". |
|
| 271 | 279 | "format, register a decoder to handle this response."); |
| 280 | + } |
|
| 272 | 281 | |
| 273 | 282 | $this->decoded_response = call_user_func( |
| 274 | 283 | $this->options['decoders'][$format], $this->response); |
@@ -189,7 +189,7 @@ |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | return $stmt->execute(); |
| 192 | - }else { |
|
| 192 | + } else { |
|
| 193 | 193 | $this->insert( $table , $data ); |
| 194 | 194 | } |
| 195 | 195 | } |