@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | - * @return mixed |
|
| 186 | + * @return callable |
|
| 187 | 187 | */ |
| 188 | 188 | public function endCallback() |
| 189 | 189 | { |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | 213 | * @param $key |
| 214 | - * @return mixed |
|
| 214 | + * @return string |
|
| 215 | 215 | */ |
| 216 | 216 | protected static function fullOption($key) |
| 217 | 217 | { |
@@ -204,7 +204,9 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public function getIni($field = null) |
| 206 | 206 | { |
| 207 | - if(!$field) return $this->options; |
|
| 207 | + if(!$field) { |
|
| 208 | + return $this->options; |
|
| 209 | + } |
|
| 208 | 210 | $full = self::fullOption($field); |
| 209 | 211 | return isset($this->options[$full]) ? $this->options[$full] : false; |
| 210 | 212 | } |
@@ -358,12 +360,15 @@ discard block |
||
| 358 | 360 | public function send($isMultiCurl = false) |
| 359 | 361 | { |
| 360 | 362 | try { |
| 361 | - if (!$this->hasInitialized) |
|
| 362 | - $this->applyOptions(); |
|
| 363 | + if (!$this->hasInitialized) { |
|
| 364 | + $this->applyOptions(); |
|
| 365 | + } |
|
| 363 | 366 | $response = $this->makeResponse($isMultiCurl); |
| 364 | 367 | $response->parse(); |
| 365 | 368 | } catch (\Exception $e) { |
| 366 | - if(!isset($response)) $response = Response::create($this, null, null, null, null); |
|
| 369 | + if(!isset($response)) { |
|
| 370 | + $response = Response::create($this, null, null, null, null); |
|
| 371 | + } |
|
| 367 | 372 | $response->error = $e->getMessage(); |
| 368 | 373 | $response->errorCode = 999; |
| 369 | 374 | } |
@@ -413,12 +418,19 @@ discard block |
||
| 413 | 418 | $this->serializeBody(); |
| 414 | 419 | |
| 415 | 420 | //try fix url |
| 416 | - if (strpos($this->options['url'], '://') === FALSE) $this->options['url'] = 'http://' . $this->options['url']; |
|
| 421 | + if (strpos($this->options['url'], '://') === FALSE) { |
|
| 422 | + $this->options['url'] = 'http://' . $this->options['url']; |
|
| 423 | + } |
|
| 417 | 424 | $components = parse_url($this->options['url']); |
| 418 | - if(FALSE === $components) throw new InvalidArgumentException('formatting url occurs error: '. $this->options['url']); |
|
| 425 | + if(FALSE === $components) { |
|
| 426 | + throw new InvalidArgumentException('formatting url occurs error: '. $this->options['url']); |
|
| 427 | + } |
|
| 419 | 428 | if($this->withURIQuery){ |
| 420 | - if(isset($components['query'])) $components['query'] .= '&'. trim($this->withURIQuery); |
|
| 421 | - else $components['query'] = trim($this->withURIQuery); |
|
| 429 | + if(isset($components['query'])) { |
|
| 430 | + $components['query'] .= '&'. trim($this->withURIQuery); |
|
| 431 | + } else { |
|
| 432 | + $components['query'] = trim($this->withURIQuery); |
|
| 433 | + } |
|
| 422 | 434 | } |
| 423 | 435 | $this->options['url'] = self::combineUrl($components); |
| 424 | 436 | |
@@ -473,7 +485,9 @@ discard block |
||
| 473 | 485 | if (isset($this->options['data'])) { |
| 474 | 486 | if (isset($this->sendMime)) { |
| 475 | 487 | $method = $this->sendMime; |
| 476 | - if (!method_exists($this, $method)) throw new InvalidOperationException($method . ' is not exists in ' . __CLASS__); |
|
| 488 | + if (!method_exists($this, $method)) { |
|
| 489 | + throw new InvalidOperationException($method . ' is not exists in ' . __CLASS__); |
|
| 490 | + } |
|
| 477 | 491 | $this->options['data'] = $this->$method($this->options['data']); |
| 478 | 492 | } else { |
| 479 | 493 | $this->options['data'] = is_array($this->options['data']) ? http_build_query($this->options['data']) : $this->options['data'];//for better compatibility |
@@ -51,7 +51,9 @@ discard block |
||
| 51 | 51 | public function unJson($body) |
| 52 | 52 | { |
| 53 | 53 | $parsed = json_decode($body, true); |
| 54 | - if(json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
| 54 | + if(json_last_error() !== JSON_ERROR_NONE) { |
|
| 55 | + throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
| 56 | + } |
|
| 55 | 57 | return $parsed; |
| 56 | 58 | } |
| 57 | 59 | |
@@ -59,7 +61,9 @@ discard block |
||
| 59 | 61 | * @return string |
| 60 | 62 | */ |
| 61 | 63 | private static function jsonLastErrorMsg(){ |
| 62 | - if(function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
| 64 | + if(function_exists('json_last_error_msg')) { |
|
| 65 | + return json_last_error_msg(); |
|
| 66 | + } |
|
| 63 | 67 | switch (json_last_error()) { |
| 64 | 68 | case JSON_ERROR_NONE: |
| 65 | 69 | return ' - No errors'; |
@@ -72,10 +72,11 @@ discard block |
||
| 72 | 72 | $headers = explode(PHP_EOL, $headers); |
| 73 | 73 | array_shift($headers); // HTTP HEADER |
| 74 | 74 | foreach ($headers as $h) { |
| 75 | - if (false !== strpos($h, ':')) |
|
| 76 | - list($k, $v) = explode(':', $h, 2); |
|
| 77 | - else |
|
| 78 | - list($k, $v) = array($h, ''); |
|
| 75 | + if (false !== strpos($h, ':')) { |
|
| 76 | + list($k, $v) = explode(':', $h, 2); |
|
| 77 | + } else { |
|
| 78 | + list($k, $v) = array($h, ''); |
|
| 79 | + } |
|
| 79 | 80 | |
| 80 | 81 | $this->header[trim($k)] = trim($v); |
| 81 | 82 | } |
@@ -96,9 +97,13 @@ discard block |
||
| 96 | 97 | public function unserializeBody() |
| 97 | 98 | { |
| 98 | 99 | if (isset($this->request->expectedMime)) { |
| 99 | - if (Mime::getFullMime($this->request->expectedMime) !== $this->contentType) throw new UnexpectedResponseException('expected mime can not be matched, real mime:'. $this->contentType. ', expected mime:'. Mime::getFullMime($this->request->expectedMime)); |
|
| 100 | + if (Mime::getFullMime($this->request->expectedMime) !== $this->contentType) { |
|
| 101 | + throw new UnexpectedResponseException('expected mime can not be matched, real mime:'. $this->contentType. ', expected mime:'. Mime::getFullMime($this->request->expectedMime)); |
|
| 102 | + } |
|
| 100 | 103 | $method = 'un'.ucfirst($this->request->expectedMime); |
| 101 | - if (!method_exists($this->request, $method)) throw new InvalidOperationException($method . ' is not exists in ' . __CLASS__); |
|
| 104 | + if (!method_exists($this->request, $method)) { |
|
| 105 | + throw new InvalidOperationException($method . ' is not exists in ' . __CLASS__); |
|
| 106 | + } |
|
| 102 | 107 | $this->body = $this->request->{$method}($this->body); |
| 103 | 108 | } |
| 104 | 109 | } |