@@ -43,12 +43,16 @@ |
||
| 43 | 43 | |
| 44 | 44 | protected function stripBom($body) |
| 45 | 45 | { |
| 46 | - if ( substr($body,0,3) === "\xef\xbb\xbf" ) // UTF-8 |
|
| 46 | + if ( substr($body,0,3) === "\xef\xbb\xbf" ) { |
|
| 47 | + // UTF-8 |
|
| 47 | 48 | $body = substr($body,3); |
| 48 | - else if ( substr($body,0,4) === "\xff\xfe\x00\x00" || substr($body,0,4) === "\x00\x00\xfe\xff" ) // UTF-32 |
|
| 49 | + } else if ( substr($body,0,4) === "\xff\xfe\x00\x00" || substr($body,0,4) === "\x00\x00\xfe\xff" ) { |
|
| 50 | + // UTF-32 |
|
| 49 | 51 | $body = substr($body,4); |
| 50 | - else if ( substr($body,0,2) === "\xff\xfe" || substr($body,0,2) === "\xfe\xff" ) // UTF-16 |
|
| 52 | + } else if ( substr($body,0,2) === "\xff\xfe" || substr($body,0,2) === "\xfe\xff" ) { |
|
| 53 | + // UTF-16 |
|
| 51 | 54 | $body = substr($body,2); |
| 55 | + } |
|
| 52 | 56 | return $body; |
| 53 | 57 | } |
| 54 | 58 | } |
| 55 | 59 | \ No newline at end of file |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public function parse($body) |
| 17 | 17 | { |
| 18 | - if (empty($body)) |
|
| 19 | - return null; |
|
| 18 | + if (empty($body)) { |
|
| 19 | + return null; |
|
| 20 | + } |
|
| 20 | 21 | |
| 21 | 22 | $parsed = array(); |
| 22 | 23 | $fp = fopen('data://text/plain;base64,' . base64_encode($body), 'r'); |
@@ -24,8 +25,9 @@ discard block |
||
| 24 | 25 | $parsed[] = $r; |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | - if (empty($parsed)) |
|
| 28 | - throw new \Exception("Unable to parse response as CSV"); |
|
| 28 | + if (empty($parsed)) { |
|
| 29 | + throw new \Exception("Unable to parse response as CSV"); |
|
| 30 | + } |
|
| 29 | 31 | return $parsed; |
| 30 | 32 | } |
| 31 | 33 | |
@@ -23,11 +23,13 @@ |
||
| 23 | 23 | public function parse($body) |
| 24 | 24 | { |
| 25 | 25 | $body = $this->stripBom($body); |
| 26 | - if (empty($body)) |
|
| 27 | - return null; |
|
| 26 | + if (empty($body)) { |
|
| 27 | + return null; |
|
| 28 | + } |
|
| 28 | 29 | $parsed = json_decode($body, $this->decode_as_array); |
| 29 | - if (is_null($parsed) && 'null' !== strtolower($body)) |
|
| 30 | - throw new \Exception("Unable to parse response as JSON"); |
|
| 30 | + if (is_null($parsed) && 'null' !== strtolower($body)) { |
|
| 31 | + throw new \Exception("Unable to parse response as JSON"); |
|
| 32 | + } |
|
| 31 | 33 | return $parsed; |
| 32 | 34 | } |
| 33 | 35 | |
@@ -37,11 +37,13 @@ |
||
| 37 | 37 | public function parse($body) |
| 38 | 38 | { |
| 39 | 39 | $body = $this->stripBom($body); |
| 40 | - if (empty($body)) |
|
| 41 | - return null; |
|
| 40 | + if (empty($body)) { |
|
| 41 | + return null; |
|
| 42 | + } |
|
| 42 | 43 | $parsed = simplexml_load_string($body, null, $this->libxml_opts, $this->namespace); |
| 43 | - if ($parsed === false) |
|
| 44 | - throw new \Exception("Unable to parse response as XML"); |
|
| 44 | + if ($parsed === false) { |
|
| 45 | + throw new \Exception("Unable to parse response as XML"); |
|
| 46 | + } |
|
| 45 | 47 | return $parsed; |
| 46 | 48 | } |
| 47 | 49 | |
@@ -138,7 +138,9 @@ |
||
| 138 | 138 | public function _parseCode($headers) |
| 139 | 139 | { |
| 140 | 140 | $end = strpos($headers, "\r\n"); |
| 141 | - if ($end === false) $end = strlen($headers); |
|
| 141 | + if ($end === false) { |
|
| 142 | + $end = strlen($headers); |
|
| 143 | + } |
|
| 142 | 144 | $parts = explode(' ', substr($headers, 0, $end)); |
| 143 | 145 | if (count($parts) < 2 || !is_numeric($parts[1])) { |
| 144 | 146 | throw new \Exception("Unable to parse response code from HTTP response due to malformed response"); |
@@ -71,7 +71,9 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | private function __construct($attrs = null) |
| 73 | 73 | { |
| 74 | - if (!is_array($attrs)) return; |
|
| 74 | + if (!is_array($attrs)) { |
|
| 75 | + return; |
|
| 76 | + } |
|
| 75 | 77 | foreach ($attrs as $attr => $value) { |
| 76 | 78 | $this->$attr = $value; |
| 77 | 79 | } |
@@ -196,8 +198,9 @@ discard block |
||
| 196 | 198 | */ |
| 197 | 199 | public function send() |
| 198 | 200 | { |
| 199 | - if (!$this->hasBeenInitialized()) |
|
| 200 | - $this->_curlPrep(); |
|
| 201 | + if (!$this->hasBeenInitialized()) { |
|
| 202 | + $this->_curlPrep(); |
|
| 203 | + } |
|
| 201 | 204 | |
| 202 | 205 | $result = curl_exec($this->_ch); |
| 203 | 206 | |
@@ -334,7 +337,9 @@ discard block |
||
| 334 | 337 | */ |
| 335 | 338 | public function mime($mime) |
| 336 | 339 | { |
| 337 | - if (empty($mime)) return $this; |
|
| 340 | + if (empty($mime)) { |
|
| 341 | + return $this; |
|
| 342 | + } |
|
| 338 | 343 | $this->content_type = $this->expected_type = Mime::getFullMime($mime); |
| 339 | 344 | if ($this->isUpload()) { |
| 340 | 345 | $this->neverSerializePayload(); |
@@ -360,7 +365,9 @@ discard block |
||
| 360 | 365 | */ |
| 361 | 366 | public function method($method) |
| 362 | 367 | { |
| 363 | - if (empty($method)) return $this; |
|
| 368 | + if (empty($method)) { |
|
| 369 | + return $this; |
|
| 370 | + } |
|
| 364 | 371 | $this->method = $method; |
| 365 | 372 | return $this; |
| 366 | 373 | } |
@@ -371,7 +378,9 @@ discard block |
||
| 371 | 378 | */ |
| 372 | 379 | public function expects($mime) |
| 373 | 380 | { |
| 374 | - if (empty($mime)) return $this; |
|
| 381 | + if (empty($mime)) { |
|
| 382 | + return $this; |
|
| 383 | + } |
|
| 375 | 384 | $this->expected_type = Mime::getFullMime($mime); |
| 376 | 385 | return $this; |
| 377 | 386 | } |
@@ -405,7 +414,9 @@ discard block |
||
| 405 | 414 | */ |
| 406 | 415 | public function contentType($mime) |
| 407 | 416 | { |
| 408 | - if (empty($mime)) return $this; |
|
| 417 | + if (empty($mime)) { |
|
| 418 | + return $this; |
|
| 419 | + } |
|
| 409 | 420 | $this->content_type = Mime::getFullMime($mime); |
| 410 | 421 | if ($this->isUpload()) { |
| 411 | 422 | $this->neverSerializePayload(); |
@@ -725,15 +736,17 @@ discard block |
||
| 725 | 736 | |
| 726 | 737 | // This method also adds the custom header support as described in the |
| 727 | 738 | // method comments |
| 728 | - if (count($args) === 0) |
|
| 729 | - return; |
|
| 739 | + if (count($args) === 0) { |
|
| 740 | + return; |
|
| 741 | + } |
|
| 730 | 742 | |
| 731 | 743 | // Strip the sugar. If it leads with "with", strip. |
| 732 | 744 | // This is okay because: No defined HTTP headers begin with with, |
| 733 | 745 | // and if you are defining a custom header, the standard is to prefix it |
| 734 | 746 | // with an "X-", so that should take care of any collisions. |
| 735 | - if (substr($method, 0, 4) === 'with') |
|
| 736 | - $method = substr($method, 4); |
|
| 747 | + if (substr($method, 0, 4) === 'with') { |
|
| 748 | + $method = substr($method, 4); |
|
| 749 | + } |
|
| 737 | 750 | |
| 738 | 751 | // Precede upper case letters with dashes, uppercase the first letter of method |
| 739 | 752 | $header = ucwords(implode('-', preg_split('/([A-Z][^A-Z]*)/', $method, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY))); |
@@ -774,11 +787,13 @@ discard block |
||
| 774 | 787 | */ |
| 775 | 788 | private function _setDefaults() |
| 776 | 789 | { |
| 777 | - if (!isset(self::$_template)) |
|
| 778 | - self::_initializeDefaults(); |
|
| 790 | + if (!isset(self::$_template)) { |
|
| 791 | + self::_initializeDefaults(); |
|
| 792 | + } |
|
| 779 | 793 | foreach (self::$_template as $k=>$v) { |
| 780 | - if ($k[0] != '_') |
|
| 781 | - $this->$k = $v; |
|
| 794 | + if ($k[0] != '_') { |
|
| 795 | + $this->$k = $v; |
|
| 796 | + } |
|
| 782 | 797 | } |
| 783 | 798 | return $this; |
| 784 | 799 | } |
@@ -808,8 +823,9 @@ discard block |
||
| 808 | 823 | Bootstrap::init(); |
| 809 | 824 | |
| 810 | 825 | // Setup the default template if need be |
| 811 | - if (!isset(self::$_template)) |
|
| 812 | - self::_initializeDefaults(); |
|
| 826 | + if (!isset(self::$_template)) { |
|
| 827 | + self::_initializeDefaults(); |
|
| 828 | + } |
|
| 813 | 829 | |
| 814 | 830 | $request = new Request(); |
| 815 | 831 | return $request |
@@ -829,8 +845,9 @@ discard block |
||
| 829 | 845 | public function _curlPrep() |
| 830 | 846 | { |
| 831 | 847 | // Check for required stuff |
| 832 | - if (!isset($this->uri)) |
|
| 833 | - throw new \Exception('Attempting to send a request before defining a URI endpoint.'); |
|
| 848 | + if (!isset($this->uri)) { |
|
| 849 | + throw new \Exception('Attempting to send a request before defining a URI endpoint.'); |
|
| 850 | + } |
|
| 834 | 851 | |
| 835 | 852 | if (isset($this->payload)) { |
| 836 | 853 | $this->serialized_payload = $this->_serializePayload($this->payload); |
@@ -853,11 +870,13 @@ discard block |
||
| 853 | 870 | |
| 854 | 871 | if ($this->hasClientSideCert()) { |
| 855 | 872 | |
| 856 | - if (!file_exists($this->client_key)) |
|
| 857 | - throw new \Exception('Could not read Client Key'); |
|
| 873 | + if (!file_exists($this->client_key)) { |
|
| 874 | + throw new \Exception('Could not read Client Key'); |
|
| 875 | + } |
|
| 858 | 876 | |
| 859 | - if (!file_exists($this->client_cert)) |
|
| 860 | - throw new \Exception('Could not read Client Certificate'); |
|
| 877 | + if (!file_exists($this->client_cert)) { |
|
| 878 | + throw new \Exception('Could not read Client Certificate'); |
|
| 879 | + } |
|
| 861 | 880 | |
| 862 | 881 | curl_setopt($ch, CURLOPT_SSLCERTTYPE, $this->client_encoding); |
| 863 | 882 | curl_setopt($ch, CURLOPT_SSLKEYTYPE, $this->client_encoding); |
@@ -884,7 +903,9 @@ discard block |
||
| 884 | 903 | // zero is safe for all curl versions |
| 885 | 904 | $verifyValue = $this->strict_ssl + 0; |
| 886 | 905 | //Support for value 1 removed in cURL 7.28.1 value 2 valid in all versions |
| 887 | - if ($verifyValue > 0) $verifyValue++; |
|
| 906 | + if ($verifyValue > 0) { |
|
| 907 | + $verifyValue++; |
|
| 908 | + } |
|
| 888 | 909 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verifyValue); |
| 889 | 910 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 890 | 911 | |
@@ -1078,12 +1099,14 @@ discard block |
||
| 1078 | 1099 | */ |
| 1079 | 1100 | private function _serializePayload($payload) |
| 1080 | 1101 | { |
| 1081 | - if (empty($payload) || $this->serialize_payload_method === self::SERIALIZE_PAYLOAD_NEVER) |
|
| 1082 | - return $payload; |
|
| 1102 | + if (empty($payload) || $this->serialize_payload_method === self::SERIALIZE_PAYLOAD_NEVER) { |
|
| 1103 | + return $payload; |
|
| 1104 | + } |
|
| 1083 | 1105 | |
| 1084 | 1106 | // When we are in "smart" mode, don't serialize strings/scalars, assume they are already serialized |
| 1085 | - if ($this->serialize_payload_method === self::SERIALIZE_PAYLOAD_SMART && is_scalar($payload)) |
|
| 1086 | - return $payload; |
|
| 1107 | + if ($this->serialize_payload_method === self::SERIALIZE_PAYLOAD_SMART && is_scalar($payload)) { |
|
| 1108 | + return $payload; |
|
| 1109 | + } |
|
| 1087 | 1110 | |
| 1088 | 1111 | // Use a custom serializer if one is registered for this mime type |
| 1089 | 1112 | if (isset($this->payload_serializers['*']) || isset($this->payload_serializers[$this->content_type])) { |
@@ -87,8 +87,9 @@ |
||
| 87 | 87 | |
| 88 | 88 | foreach ($handlers as $mime => $handler) { |
| 89 | 89 | // Don't overwrite if the handler has already been registered |
| 90 | - if (Httpful::hasParserRegistered($mime)) |
|
| 91 | - continue; |
|
| 90 | + if (Httpful::hasParserRegistered($mime)) { |
|
| 91 | + continue; |
|
| 92 | + } |
|
| 92 | 93 | Httpful::register($mime, $handler); |
| 93 | 94 | } |
| 94 | 95 | |