@@ -81,10 +81,11 @@ discard block |
||
| 81 | 81 | * @param[in] integer $since Sequence number to start results. Allowed values: positive integers | 'now'. |
| 82 | 82 | */ |
| 83 | 83 | public function setSince($since = 0) { |
| 84 | - if (($since == "now") or (is_int($since) and ($since >= 0))) |
|
| 85 | - $this->options["since"] = $since; |
|
| 86 | - else |
|
| 87 | - throw new \InvalidArgumentException("\$since must be a non-negative integer or can be 'now'."); |
|
| 84 | + if (($since == "now") or (is_int($since) and ($since >= 0))) { |
|
| 85 | + $this->options["since"] = $since; |
|
| 86 | + } else { |
|
| 87 | + throw new \InvalidArgumentException("\$since must be a non-negative integer or can be 'now'."); |
|
| 88 | + } |
|
| 88 | 89 | |
| 89 | 90 | return $this; |
| 90 | 91 | } |
@@ -95,10 +96,11 @@ discard block |
||
| 95 | 96 | * @param[in] integer $limit Maximum number of rows to return. Must be a positive integer. |
| 96 | 97 | */ |
| 97 | 98 | public function setLimit($limit) { |
| 98 | - if (is_int($limit) and ($limit > 0)) |
|
| 99 | - $this->options["limit"] = $limit; |
|
| 100 | - else |
|
| 101 | - throw new \InvalidArgumentException("\$value must be a positive integer."); |
|
| 99 | + if (is_int($limit) and ($limit > 0)) { |
|
| 100 | + $this->options["limit"] = $limit; |
|
| 101 | + } else { |
|
| 102 | + throw new \InvalidArgumentException("\$value must be a positive integer."); |
|
| 103 | + } |
|
| 102 | 104 | |
| 103 | 105 | return $this; |
| 104 | 106 | } |
@@ -117,10 +119,11 @@ discard block |
||
| 117 | 119 | * @param[in] string $type Type of feed. |
| 118 | 120 | */ |
| 119 | 121 | public function setFeedType($type) { |
| 120 | - if (array_key_exists($type, self::$supportedTypes)) |
|
| 121 | - $this->options["feed"] = $type; |
|
| 122 | - else |
|
| 123 | - throw new \InvalidArgumentException("Invalid feed type."); |
|
| 122 | + if (array_key_exists($type, self::$supportedTypes)) { |
|
| 123 | + $this->options["feed"] = $type; |
|
| 124 | + } else { |
|
| 125 | + throw new \InvalidArgumentException("Invalid feed type."); |
|
| 126 | + } |
|
| 124 | 127 | } |
| 125 | 128 | |
| 126 | 129 | |
@@ -130,10 +133,11 @@ discard block |
||
| 130 | 133 | * @param[in] bool $style The feed style. |
| 131 | 134 | */ |
| 132 | 135 | public function setStyle($style) { |
| 133 | - if (array_key_exists($style, self::$supportedStyles)) |
|
| 134 | - $this->options["style"] = $style; |
|
| 135 | - else |
|
| 136 | - throw new \InvalidArgumentException("Invalid feed style."); |
|
| 136 | + if (array_key_exists($style, self::$supportedStyles)) { |
|
| 137 | + $this->options["style"] = $style; |
|
| 138 | + } else { |
|
| 139 | + throw new \InvalidArgumentException("Invalid feed style."); |
|
| 140 | + } |
|
| 137 | 141 | } |
| 138 | 142 | |
| 139 | 143 | |
@@ -146,11 +150,12 @@ discard block |
||
| 146 | 150 | public function setHeartbeat($heartbeat = self::DEFAULT_HEARTBEAT) { |
| 147 | 151 | $feed = $this->options['feed']; |
| 148 | 152 | |
| 149 | - if (($feed == self::CONTINUOUS_TYPE) or ($feed == self::LONGPOLL_TYPE)) |
|
| 150 | - if (is_int($heartbeat) and ($heartbeat >= 0)) |
|
| 153 | + if (($feed == self::CONTINUOUS_TYPE) or ($feed == self::LONGPOLL_TYPE)) { |
|
| 154 | + if (is_int($heartbeat) and ($heartbeat >= 0)) |
|
| 151 | 155 | $this->options["heartbeat"] = $heartbeat; |
| 152 | - else |
|
| 153 | - throw new \InvalidArgumentException("\$heartbeat must be a non-negative integer."); |
|
| 156 | + } else { |
|
| 157 | + throw new \InvalidArgumentException("\$heartbeat must be a non-negative integer."); |
|
| 158 | + } |
|
| 154 | 159 | } |
| 155 | 160 | |
| 156 | 161 | |
@@ -163,11 +168,12 @@ discard block |
||
| 163 | 168 | public function setTimeout($timeout = self::DEFAULT_TIMEOUT) { |
| 164 | 169 | $feed = $this->options['feed']; |
| 165 | 170 | |
| 166 | - if (($feed == self::CONTINUOUS_TYPE) or ($feed == self::LONGPOLL_TYPE)) |
|
| 167 | - if (is_int($timeout) and ($timeout > 0)) |
|
| 171 | + if (($feed == self::CONTINUOUS_TYPE) or ($feed == self::LONGPOLL_TYPE)) { |
|
| 172 | + if (is_int($timeout) and ($timeout > 0)) |
|
| 168 | 173 | $this->options["timeout"] = $timeout; |
| 169 | - else |
|
| 170 | - throw new \InvalidArgumentException("\$timeout must be a positive integer."); |
|
| 174 | + } else { |
|
| 175 | + throw new \InvalidArgumentException("\$timeout must be a positive integer."); |
|
| 176 | + } |
|
| 171 | 177 | } |
| 172 | 178 | |
| 173 | 179 | |
@@ -63,10 +63,11 @@ discard block |
||
| 63 | 63 | * @param[in] string $type Type of feed. |
| 64 | 64 | */ |
| 65 | 65 | public function setFeedType($type) { |
| 66 | - if (array_key_exists($type, self::$supportedTypes)) |
|
| 67 | - $this->options["feed"] = $type; |
|
| 68 | - else |
|
| 69 | - throw new \InvalidArgumentException("Invalid feed type."); |
|
| 66 | + if (array_key_exists($type, self::$supportedTypes)) { |
|
| 67 | + $this->options["feed"] = $type; |
|
| 68 | + } else { |
|
| 69 | + throw new \InvalidArgumentException("Invalid feed type."); |
|
| 70 | + } |
|
| 70 | 71 | |
| 71 | 72 | return $this; |
| 72 | 73 | } |
@@ -81,11 +82,12 @@ discard block |
||
| 81 | 82 | public function setTimeout($timeout = self::DEFAULT_TIMEOUT) { |
| 82 | 83 | $feed = $this->options['feed']; |
| 83 | 84 | |
| 84 | - if ($feed == self::CONTINUOUS_TYPE) |
|
| 85 | - if (is_int($timeout) and ($timeout > 0)) |
|
| 85 | + if ($feed == self::CONTINUOUS_TYPE) { |
|
| 86 | + if (is_int($timeout) and ($timeout > 0)) |
|
| 86 | 87 | $this->options["timeout"] = $timeout; |
| 87 | - else |
|
| 88 | - throw new \InvalidArgumentException("\$timeout must be a positive integer."); |
|
| 88 | + } else { |
|
| 89 | + throw new \InvalidArgumentException("\$timeout must be a positive integer."); |
|
| 90 | + } |
|
| 89 | 91 | |
| 90 | 92 | return $this; |
| 91 | 93 | } |
@@ -143,10 +143,11 @@ |
||
| 143 | 143 | * @param[in] string|array $revs The revision(s) identifier(s). |
| 144 | 144 | */ |
| 145 | 145 | public function includeOpenRevs($revs = 'all') { |
| 146 | - if (is_array($revs)) |
|
| 147 | - $this->options['open_revs'] = json_encode($revs); |
|
| 148 | - else |
|
| 149 | - $this->options['open_revs'] = 'all'; |
|
| 146 | + if (is_array($revs)) { |
|
| 147 | + $this->options['open_revs'] = json_encode($revs); |
|
| 148 | + } else { |
|
| 149 | + $this->options['open_revs'] = 'all'; |
|
| 150 | + } |
|
| 150 | 151 | |
| 151 | 152 | return $this; |
| 152 | 153 | } |
@@ -206,8 +206,9 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | public function getHeaderAsArray() { |
| 208 | 208 | $wellformedHeader = []; |
| 209 | - foreach ($this->header as $name => $value) |
|
| 210 | - $wellformedHeader[] = $name.": ".$value; |
|
| 209 | + foreach ($this->header as $name => $value) { |
|
| 210 | + $wellformedHeader[] = $name.": ".$value; |
|
| 211 | + } |
|
| 211 | 212 | |
| 212 | 213 | return $wellformedHeader; |
| 213 | 214 | } |
@@ -238,10 +239,11 @@ discard block |
||
| 238 | 239 | * @retval string |
| 239 | 240 | */ |
| 240 | 241 | public function getHeaderFieldValue($name) { |
| 241 | - if ($this->hasHeaderField($name)) |
|
| 242 | - return $this->header[$name]; |
|
| 243 | - else |
|
| 244 | - return FALSE; |
|
| 242 | + if ($this->hasHeaderField($name)) { |
|
| 243 | + return $this->header[$name]; |
|
| 244 | + } else { |
|
| 245 | + return FALSE; |
|
| 246 | + } |
|
| 245 | 247 | } |
| 246 | 248 | |
| 247 | 249 | |
@@ -251,10 +253,11 @@ discard block |
||
| 251 | 253 | * @param[in] string $value The header field value. |
| 252 | 254 | */ |
| 253 | 255 | public function setHeaderField($name, $value) { |
| 254 | - if (array_key_exists($name, static::$supportedHeaderFields)) |
|
| 255 | - $this->header[$name] = $value; |
|
| 256 | - else |
|
| 257 | - throw new \Exception("$name header field is not supported."); |
|
| 256 | + if (array_key_exists($name, static::$supportedHeaderFields)) { |
|
| 257 | + $this->header[$name] = $value; |
|
| 258 | + } else { |
|
| 259 | + throw new \Exception("$name header field is not supported."); |
|
| 260 | + } |
|
| 258 | 261 | } |
| 259 | 262 | |
| 260 | 263 | |
@@ -263,8 +266,9 @@ discard block |
||
| 263 | 266 | * @param[in] string $name The header field name. |
| 264 | 267 | */ |
| 265 | 268 | public function removeHeaderField($name) { |
| 266 | - if (array_key_exists($name, static::$supportedHeaderFields)) |
|
| 267 | - unset($this->header[$name]); |
|
| 269 | + if (array_key_exists($name, static::$supportedHeaderFields)) { |
|
| 270 | + unset($this->header[$name]); |
|
| 271 | + } |
|
| 268 | 272 | } |
| 269 | 273 | |
| 270 | 274 | |
@@ -273,11 +277,12 @@ discard block |
||
| 273 | 277 | * @param[in] array $headerFields An associative array of header fields. |
| 274 | 278 | */ |
| 275 | 279 | public function setMultipleHeaderFieldsAtOnce(array $headerFields) { |
| 276 | - if (Helper\ArrayHelper::isAssociative($headerFields)) |
|
| 277 | - foreach ($headerFields as $name => $value) |
|
| 280 | + if (Helper\ArrayHelper::isAssociative($headerFields)) { |
|
| 281 | + foreach ($headerFields as $name => $value) |
|
| 278 | 282 | $this->setHeaderField($name, $value); |
| 279 | - else |
|
| 280 | - throw new \Exception("\$headerFields must be an associative array."); |
|
| 283 | + } else { |
|
| 284 | + throw new \Exception("\$headerFields must be an associative array."); |
|
| 285 | + } |
|
| 281 | 286 | } |
| 282 | 287 | |
| 283 | 288 | |
@@ -286,10 +291,11 @@ discard block |
||
| 286 | 291 | * @param[in] string $name Header field name. |
| 287 | 292 | */ |
| 288 | 293 | public static function addCustomHeaderField($name) { |
| 289 | - if (array_key_exists($name, static::$supportedHeaderFields)) |
|
| 290 | - throw new \Exception("$name header field is supported but already exists."); |
|
| 291 | - else |
|
| 292 | - static::$supportedHeaderFields[] = $name; |
|
| 294 | + if (array_key_exists($name, static::$supportedHeaderFields)) { |
|
| 295 | + throw new \Exception("$name header field is supported but already exists."); |
|
| 296 | + } else { |
|
| 297 | + static::$supportedHeaderFields[] = $name; |
|
| 298 | + } |
|
| 293 | 299 | } |
| 294 | 300 | |
| 295 | 301 | |
@@ -68,9 +68,10 @@ |
||
| 68 | 68 | $this->scheme = isset($matches['scheme']) ? $matches['scheme'] : "tcp://"; |
| 69 | 69 | $this->host = isset($matches['host']) ? $matches['host'] : self::DEFAULT_HOST; |
| 70 | 70 | $this->port = isset($matches['port']) ? substr($matches['port'], 1) : self::DEFAULT_PORT; |
| 71 | - } |
|
| 72 | - else // Match attempt failed. |
|
| 71 | + } else { |
|
| 72 | + // Match attempt failed. |
|
| 73 | 73 | throw new \InvalidArgumentException(sprintf("'%s' is not a valid URI.", $server)); |
| 74 | + } |
|
| 74 | 75 | |
| 75 | 76 | $this->userName = (string)$userName; |
| 76 | 77 | $this->password = (string)$password; |
@@ -52,8 +52,9 @@ discard block |
||
| 52 | 52 | * @copydoc AbstractAdapter::initialize() |
| 53 | 53 | */ |
| 54 | 54 | public function initialize() { |
| 55 | - if (!extension_loaded("curl")) |
|
| 56 | - throw new \RuntimeException("The cURL extension is not loaded."); |
|
| 55 | + if (!extension_loaded("curl")) { |
|
| 56 | + throw new \RuntimeException("The cURL extension is not loaded."); |
|
| 57 | + } |
|
| 57 | 58 | } |
| 58 | 59 | |
| 59 | 60 | |
@@ -64,8 +65,9 @@ discard block |
||
| 64 | 65 | $opts = []; |
| 65 | 66 | |
| 66 | 67 | // Resets all the cURL options. The curl_reset() function is available only since PHP 5.5. |
| 67 | - if (function_exists('curl_reset')) |
|
| 68 | - curl_reset($this->handle); |
|
| 68 | + if (function_exists('curl_reset')) { |
|
| 69 | + curl_reset($this->handle); |
|
| 70 | + } |
|
| 69 | 71 | |
| 70 | 72 | // Sets the methods and its related options. |
| 71 | 73 | switch ($request->getMethod()) { |
@@ -100,9 +102,9 @@ discard block |
||
| 100 | 102 | |
| 101 | 103 | $opts[CURLOPT_INFILE] = $fd; |
| 102 | 104 | $opts[CURLOPT_INFILESIZE] = $request->getBodyLength(); |
| 105 | + } else { |
|
| 106 | + throw new \RuntimeException("Cannot create the stream."); |
|
| 103 | 107 | } |
| 104 | - else |
|
| 105 | - throw new \RuntimeException("Cannot create the stream."); |
|
| 106 | 108 | } |
| 107 | 109 | |
| 108 | 110 | break; |
@@ -143,8 +145,9 @@ discard block |
||
| 143 | 145 | // This fix a known cURL bug: see http://the-stickman.com/web-development/php-and-curl-disabling-100-continue-header/ |
| 144 | 146 | // cURL sets the Expect header field automatically, ignoring the fact that a client may not need it for the specific |
| 145 | 147 | // request. |
| 146 | - if (!$request->hasHeaderField(Request::EXPECT_HF)) |
|
| 147 | - curl_setopt($this->handle, CURLOPT_HTTPHEADER, array("Expect:")); |
|
| 148 | + if (!$request->hasHeaderField(Request::EXPECT_HF)) { |
|
| 149 | + curl_setopt($this->handle, CURLOPT_HTTPHEADER, array("Expect:")); |
|
| 150 | + } |
|
| 148 | 151 | |
| 149 | 152 | // Sets the request header. |
| 150 | 153 | // Due to a stupid bug, using curl_setopt_array(), cURL doesn't override the Content-Type header field. So we must |
@@ -176,8 +179,7 @@ discard block |
||
| 176 | 179 | $response = new Response($header); |
| 177 | 180 | $response->setBody($result); |
| 178 | 181 | return $response; |
| 179 | - } |
|
| 180 | - else { |
|
| 182 | + } else { |
|
| 181 | 183 | $error = curl_error($this->handle); |
| 182 | 184 | throw new \RuntimeException($error); |
| 183 | 185 | } |
@@ -144,8 +144,9 @@ discard block |
||
| 144 | 144 | public static function checkFn($fnImpl, $fnDef, $fnRegex) { |
| 145 | 145 | Lint::checkSourceCode($fnImpl); |
| 146 | 146 | |
| 147 | - if (!preg_match($fnRegex, $fnImpl)) |
|
| 148 | - throw new \Exception("The \$closure must be defined like: $fnDef"); |
|
| 147 | + if (!preg_match($fnRegex, $fnImpl)) { |
|
| 148 | + throw new \Exception("The \$closure must be defined like: $fnDef"); |
|
| 149 | + } |
|
| 149 | 150 | } |
| 150 | 151 | |
| 151 | 152 | |
@@ -153,14 +154,17 @@ discard block |
||
| 153 | 154 | $view = []; |
| 154 | 155 | $view['map'] = $this->mapFn; |
| 155 | 156 | |
| 156 | - if (!empty($this->language)) |
|
| 157 | - $view['language'] = $this->language; |
|
| 157 | + if (!empty($this->language)) { |
|
| 158 | + $view['language'] = $this->language; |
|
| 159 | + } |
|
| 158 | 160 | |
| 159 | - if (!empty($this->reduceFn)) |
|
| 160 | - $view['reduce'] = $this->reduceFn; |
|
| 161 | + if (!empty($this->reduceFn)) { |
|
| 162 | + $view['reduce'] = $this->reduceFn; |
|
| 163 | + } |
|
| 161 | 164 | |
| 162 | - if (!empty($this->options)) |
|
| 163 | - $view['options'] = $this->options; |
|
| 165 | + if (!empty($this->options)) { |
|
| 166 | + $view['options'] = $this->options; |
|
| 167 | + } |
|
| 164 | 168 | |
| 165 | 169 | return $view; |
| 166 | 170 | } |
@@ -225,8 +229,9 @@ discard block |
||
| 225 | 229 | public function setMapFn($value) { |
| 226 | 230 | $fn = stripslashes((string)$value); |
| 227 | 231 | |
| 228 | - if ($this->language == "php") |
|
| 229 | - self::checkFn($fn, self::MAP_DEFINITION, self::MAP_REGEX); |
|
| 232 | + if ($this->language == "php") { |
|
| 233 | + self::checkFn($fn, self::MAP_DEFINITION, self::MAP_REGEX); |
|
| 234 | + } |
|
| 230 | 235 | |
| 231 | 236 | $this->mapFn = $fn; |
| 232 | 237 | } |
@@ -240,8 +245,9 @@ discard block |
||
| 240 | 245 | public function setReduceFn($value) { |
| 241 | 246 | $fn = stripslashes((string)$value); |
| 242 | 247 | |
| 243 | - if ($this->language == "php") |
|
| 244 | - self::checkFn($fn, self::REDUCE_DEFINITION, self::REDUCE_REGEX); |
|
| 248 | + if ($this->language == "php") { |
|
| 249 | + self::checkFn($fn, self::REDUCE_DEFINITION, self::REDUCE_REGEX); |
|
| 250 | + } |
|
| 245 | 251 | |
| 246 | 252 | $this->reduceFn = $fn; |
| 247 | 253 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * arrays. |
| 55 | 55 | * @retval array An array of rows. |
| 56 | 56 | */ |
| 57 | - public function asArray() { |
|
| 57 | + public function asArray() { |
|
| 58 | 58 | return $this->result['rows']; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param[in] integer $offset The offset to retrieve. |
| 106 | 106 | * @retval mixed Can return all value types. |
| 107 | 107 | */ |
| 108 | - public function offsetGet($offset) { |
|
| 108 | + public function offsetGet($offset) { |
|
| 109 | 109 | return $this->result['rows'][$offset]; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | /** |
| 48 | 48 | * @copydoc AbstractAdapter::__construct() |
| 49 | 49 | * @param[in] bool $persistent (optional) When `true` the client uses a persistent connection. |
| 50 | - */ |
|
| 50 | + */ |
|
| 51 | 51 | public function __construct($server = parent::DEFAULT_SERVER, $userName = "", $password = "", $persistent = TRUE) { |
| 52 | 52 | $this->initialize(); |
| 53 | 53 | |
@@ -56,13 +56,15 @@ discard block |
||
| 56 | 56 | $this->timeout = static::$defaultSocketTimeout; |
| 57 | 57 | |
| 58 | 58 | // Establishes a connection within the server. |
| 59 | - if ($persistent) |
|
| 60 | - $this->handle = @pfsockopen($this->scheme.$this->host, $this->port, $errno, $errstr, $this->timeout); |
|
| 61 | - else |
|
| 62 | - $this->handle = @fsockopen($this->scheme.$this->host, $this->port, $errno, $errstr, $this->timeout); |
|
| 59 | + if ($persistent) { |
|
| 60 | + $this->handle = @pfsockopen($this->scheme.$this->host, $this->port, $errno, $errstr, $this->timeout); |
|
| 61 | + } else { |
|
| 62 | + $this->handle = @fsockopen($this->scheme.$this->host, $this->port, $errno, $errstr, $this->timeout); |
|
| 63 | + } |
|
| 63 | 64 | |
| 64 | - if (!is_resource($this->handle)) |
|
| 65 | - throw new \ErrorException($errstr, $errno); |
|
| 65 | + if (!is_resource($this->handle)) { |
|
| 66 | + throw new \ErrorException($errstr, $errno); |
|
| 67 | + } |
|
| 66 | 68 | } |
| 67 | 69 | |
| 68 | 70 | |
@@ -123,8 +125,9 @@ discard block |
||
| 123 | 125 | $statusCodeAndHeader .= $buffer; |
| 124 | 126 | |
| 125 | 127 | // The header is separated from the body by a newline, so we break when we read it. |
| 126 | - if ($buffer == Message::CRLF) |
|
| 127 | - break; |
|
| 128 | + if ($buffer == Message::CRLF) { |
|
| 129 | + break; |
|
| 130 | + } |
|
| 128 | 131 | } |
| 129 | 132 | |
| 130 | 133 | return $statusCodeAndHeader; |
@@ -144,18 +147,21 @@ discard block |
||
| 144 | 147 | |
| 145 | 148 | // If it's only a newline, this normally means it's read the total amount of data requested minus the newline |
| 146 | 149 | // continue to next loop to make sure we're done. |
| 147 | - if ($line == Message::CRLF) |
|
| 148 | - continue; |
|
| 150 | + if ($line == Message::CRLF) { |
|
| 151 | + continue; |
|
| 152 | + } |
|
| 149 | 153 | |
| 150 | 154 | // The length of the block is expressed in hexadecimal. |
| 151 | 155 | $length = hexdec($line); |
| 152 | 156 | |
| 153 | - if (!is_int($length)) |
|
| 154 | - throw new \RuntimeException("The response doesn't seem chunk encoded."); |
|
| 157 | + if (!is_int($length)) { |
|
| 158 | + throw new \RuntimeException("The response doesn't seem chunk encoded."); |
|
| 159 | + } |
|
| 155 | 160 | |
| 156 | 161 | // Zero is sent when at the end of the chunks or the end of the stream. |
| 157 | - if ($length < 1) |
|
| 158 | - break; |
|
| 162 | + if ($length < 1) { |
|
| 163 | + break; |
|
| 164 | + } |
|
| 159 | 165 | |
| 160 | 166 | // Reads the chunk. |
| 161 | 167 | // When reading from network streams or pipes, such as those returned when reading remote files or from popen() |
@@ -168,18 +174,21 @@ discard block |
||
| 168 | 174 | $size = min(self::BUFFER_LENGTH, $length); |
| 169 | 175 | $data = fread($this->handle, $size); |
| 170 | 176 | |
| 171 | - if (strlen($data) == 0) |
|
| 172 | - break; // EOF |
|
| 177 | + if (strlen($data) == 0) { |
|
| 178 | + break; |
|
| 179 | + } |
|
| 180 | + // EOF |
|
| 173 | 181 | |
| 174 | 182 | $buffer .= $data; |
| 175 | 183 | $length -= strlen($data); |
| 176 | 184 | } |
| 177 | 185 | |
| 178 | 186 | // If a function has been hooked, calls it, else just adds the buffer to the body. |
| 179 | - if (is_null($chunkHook)) |
|
| 180 | - $body .= $buffer; |
|
| 181 | - else |
|
| 182 | - $chunkHook->process($buffer); |
|
| 187 | + if (is_null($chunkHook)) { |
|
| 188 | + $body .= $buffer; |
|
| 189 | + } else { |
|
| 190 | + $chunkHook->process($buffer); |
|
| 191 | + } |
|
| 183 | 192 | } |
| 184 | 193 | |
| 185 | 194 | // A chunk response might have some footer, but CouchDB doesn't use them, so we simply ignore them. |
@@ -188,8 +197,9 @@ discard block |
||
| 188 | 197 | $buffer = fgets($this->handle, self::BUFFER_LENGTH); |
| 189 | 198 | |
| 190 | 199 | // The chunk response ends with a newline, so we break when we read it. |
| 191 | - if ($buffer == Message::CRLF) |
|
| 192 | - break; |
|
| 200 | + if ($buffer == Message::CRLF) { |
|
| 201 | + break; |
|
| 202 | + } |
|
| 193 | 203 | } |
| 194 | 204 | |
| 195 | 205 | return $body; |
@@ -216,8 +226,9 @@ discard block |
||
| 216 | 226 | $body .= $buffer; |
| 217 | 227 | $bytes += strlen($buffer); |
| 218 | 228 | |
| 219 | - if ($bytes >= $length) |
|
| 220 | - break; |
|
| 229 | + if ($bytes >= $length) { |
|
| 230 | + break; |
|
| 231 | + } |
|
| 221 | 232 | } |
| 222 | 233 | } |
| 223 | 234 | |
@@ -232,10 +243,11 @@ discard block |
||
| 232 | 243 | * @return string |
| 233 | 244 | */ |
| 234 | 245 | protected function readResponseBody(Response $response, $chunkHook) { |
| 235 | - if ($response->getHeaderFieldValue(Response::TRANSFER_ENCODING_HF) == "chunked") |
|
| 236 | - return $this->readChunkedResponseBody($chunkHook); |
|
| 237 | - else |
|
| 238 | - return $this->readStandardResponseBody($response); |
|
| 246 | + if ($response->getHeaderFieldValue(Response::TRANSFER_ENCODING_HF) == "chunked") { |
|
| 247 | + return $this->readChunkedResponseBody($chunkHook); |
|
| 248 | + } else { |
|
| 249 | + return $this->readStandardResponseBody($response); |
|
| 250 | + } |
|
| 239 | 251 | } |
| 240 | 252 | |
| 241 | 253 | |
@@ -245,12 +257,14 @@ discard block |
||
| 245 | 257 | public function send(Request $request, IChunkHook $chunkHook = NULL) { |
| 246 | 258 | $request->setHeaderField(Request::HOST_HF, $this->host.":".$this->port); |
| 247 | 259 | |
| 248 | - if (!empty($this->userName)) |
|
| 249 | - $request->setBasicAuth($this->userName, $this->password); |
|
| 260 | + if (!empty($this->userName)) { |
|
| 261 | + $request->setBasicAuth($this->userName, $this->password); |
|
| 262 | + } |
|
| 250 | 263 | |
| 251 | 264 | // Sets the Content-Length header only when the given request has a message body. |
| 252 | - if ($request->hasBody()) |
|
| 253 | - $request->setHeaderField(Message::CONTENT_LENGTH_HF, $request->getBodyLength()); |
|
| 265 | + if ($request->hasBody()) { |
|
| 266 | + $request->setHeaderField(Message::CONTENT_LENGTH_HF, $request->getBodyLength()); |
|
| 267 | + } |
|
| 254 | 268 | |
| 255 | 269 | // Writes the request over the socket. |
| 256 | 270 | $this->writeRequest($request); |