@@ -47,7 +47,7 @@ |
||
47 | 47 | /** |
48 | 48 | * @copydoc AbstractAdapter::__construct() |
49 | 49 | * @param 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; |
@@ -145,18 +148,21 @@ discard block |
||
145 | 148 | |
146 | 149 | // If it's only a newline, this normally means it's read the total amount of data requested minus the newline |
147 | 150 | // continue to next loop to make sure we're done. |
148 | - if ($line == Message::CRLF) |
|
149 | - continue; |
|
151 | + if ($line == Message::CRLF) { |
|
152 | + continue; |
|
153 | + } |
|
150 | 154 | |
151 | 155 | // The length of the block is expressed in hexadecimal. |
152 | 156 | $length = hexdec($line); |
153 | 157 | |
154 | - if (!is_int($length)) |
|
155 | - throw new \RuntimeException("The response doesn't seem chunk encoded."); |
|
158 | + if (!is_int($length)) { |
|
159 | + throw new \RuntimeException("The response doesn't seem chunk encoded."); |
|
160 | + } |
|
156 | 161 | |
157 | 162 | // Zero is sent when at the end of the chunks or the end of the stream. |
158 | - if ($length < 1) |
|
159 | - break; |
|
163 | + if ($length < 1) { |
|
164 | + break; |
|
165 | + } |
|
160 | 166 | |
161 | 167 | // Reads the chunk. |
162 | 168 | // When reading from network streams or pipes, such as those returned when reading remote files or from popen() |
@@ -169,18 +175,21 @@ discard block |
||
169 | 175 | $size = min(self::BUFFER_LENGTH, $length); |
170 | 176 | $data = fread($this->handle, $size); |
171 | 177 | |
172 | - if (strlen($data) == 0) |
|
173 | - break; // EOF |
|
178 | + if (strlen($data) == 0) { |
|
179 | + break; |
|
180 | + } |
|
181 | + // EOF |
|
174 | 182 | |
175 | 183 | $buffer .= $data; |
176 | 184 | $length -= strlen($data); |
177 | 185 | } |
178 | 186 | |
179 | 187 | // If a function has been hooked, calls it, else just adds the buffer to the body. |
180 | - if (is_null($chunkHook)) |
|
181 | - $body .= $buffer; |
|
182 | - else |
|
183 | - $chunkHook->process($buffer); |
|
188 | + if (is_null($chunkHook)) { |
|
189 | + $body .= $buffer; |
|
190 | + } else { |
|
191 | + $chunkHook->process($buffer); |
|
192 | + } |
|
184 | 193 | } |
185 | 194 | |
186 | 195 | // A chunk response might have some footer, but CouchDB doesn't use them, so we simply ignore them. |
@@ -189,8 +198,9 @@ discard block |
||
189 | 198 | $buffer = fgets($this->handle, self::BUFFER_LENGTH); |
190 | 199 | |
191 | 200 | // The chunk response ends with a newline, so we break when we read it. |
192 | - if ($buffer == Message::CRLF) |
|
193 | - break; |
|
201 | + if ($buffer == Message::CRLF) { |
|
202 | + break; |
|
203 | + } |
|
194 | 204 | } |
195 | 205 | |
196 | 206 | return $body; |
@@ -217,8 +227,9 @@ discard block |
||
217 | 227 | $body .= $buffer; |
218 | 228 | $bytes += strlen($buffer); |
219 | 229 | |
220 | - if ($bytes >= $length) |
|
221 | - break; |
|
230 | + if ($bytes >= $length) { |
|
231 | + break; |
|
232 | + } |
|
222 | 233 | } |
223 | 234 | } |
224 | 235 | |
@@ -233,10 +244,11 @@ discard block |
||
233 | 244 | * @return string |
234 | 245 | */ |
235 | 246 | protected function readResponseBody(Response $response, $chunkHook) { |
236 | - if ($response->getHeaderFieldValue(Response::TRANSFER_ENCODING_HF) == "chunked") |
|
237 | - return $this->readChunkedResponseBody($chunkHook); |
|
238 | - else |
|
239 | - return $this->readStandardResponseBody($response); |
|
247 | + if ($response->getHeaderFieldValue(Response::TRANSFER_ENCODING_HF) == "chunked") { |
|
248 | + return $this->readChunkedResponseBody($chunkHook); |
|
249 | + } else { |
|
250 | + return $this->readStandardResponseBody($response); |
|
251 | + } |
|
240 | 252 | } |
241 | 253 | |
242 | 254 | |
@@ -246,12 +258,14 @@ discard block |
||
246 | 258 | public function send(Request $request, IChunkHook $chunkHook = NULL) { |
247 | 259 | $request->setHeaderField(Request::HOST_HF, $this->host.":".$this->port); |
248 | 260 | |
249 | - if (!empty($this->userName)) |
|
250 | - $request->setBasicAuth($this->userName, $this->password); |
|
261 | + if (!empty($this->userName)) { |
|
262 | + $request->setBasicAuth($this->userName, $this->password); |
|
263 | + } |
|
251 | 264 | |
252 | 265 | // Sets the Content-Length header only when the given request has a message body. |
253 | - if ($request->hasBody()) |
|
254 | - $request->setHeaderField(Message::CONTENT_LENGTH_HF, $request->getBodyLength()); |
|
266 | + if ($request->hasBody()) { |
|
267 | + $request->setHeaderField(Message::CONTENT_LENGTH_HF, $request->getBodyLength()); |
|
268 | + } |
|
255 | 269 | |
256 | 270 | // Writes the request over the socket. |
257 | 271 | $this->writeRequest($request); |
@@ -423,13 +423,15 @@ discard block |
||
423 | 423 | */ |
424 | 424 | protected function parseStatusCode($rawMessage) { |
425 | 425 | $matches = []; |
426 | - if (preg_match('%HTTP/1\.[0-1] (\d\d\d) %', $rawMessage, $matches)) |
|
427 | - $this->statusCode = $matches[1]; |
|
428 | - else |
|
429 | - throw new \UnexpectedValueException("HTTP Status Code undefined."); |
|
426 | + if (preg_match('%HTTP/1\.[0-1] (\d\d\d) %', $rawMessage, $matches)) { |
|
427 | + $this->statusCode = $matches[1]; |
|
428 | + } else { |
|
429 | + throw new \UnexpectedValueException("HTTP Status Code undefined."); |
|
430 | + } |
|
430 | 431 | |
431 | - if (!array_key_exists($this->statusCode, self::$supportedStatusCodes)) |
|
432 | - throw new \UnexpectedValueException("HTTP Status Code unknown."); |
|
432 | + if (!array_key_exists($this->statusCode, self::$supportedStatusCodes)) { |
|
433 | + throw new \UnexpectedValueException("HTTP Status Code unknown."); |
|
434 | + } |
|
433 | 435 | } |
434 | 436 | |
435 | 437 | |
@@ -449,10 +451,11 @@ discard block |
||
449 | 451 | }, |
450 | 452 | strtolower(trim($matches[1]))); |
451 | 453 | |
452 | - if (isset($this->header[$matches[1]])) |
|
453 | - $this->header[$matches[1]] = array($this->header[$matches[1]], $matches[2]); |
|
454 | - else |
|
455 | - $this->header[$matches[1]] = trim($matches[2]); |
|
454 | + if (isset($this->header[$matches[1]])) { |
|
455 | + $this->header[$matches[1]] = array($this->header[$matches[1]], $matches[2]); |
|
456 | + } else { |
|
457 | + $this->header[$matches[1]] = trim($matches[2]); |
|
458 | + } |
|
456 | 459 | } |
457 | 460 | } |
458 | 461 | } |
@@ -463,11 +466,13 @@ discard block |
||
463 | 466 | * @param string $rawMessage The raw message. |
464 | 467 | */ |
465 | 468 | protected function parseStatusCodeAndHeader($rawMessage) { |
466 | - if (!is_string($rawMessage)) |
|
467 | - throw new \InvalidArgumentException("\$rawMessage must be a string."); |
|
469 | + if (!is_string($rawMessage)) { |
|
470 | + throw new \InvalidArgumentException("\$rawMessage must be a string."); |
|
471 | + } |
|
468 | 472 | |
469 | - if (empty($rawMessage)) |
|
470 | - throw new \UnexpectedValueException("\$rawMessage is null."); |
|
473 | + if (empty($rawMessage)) { |
|
474 | + throw new \UnexpectedValueException("\$rawMessage is null."); |
|
475 | + } |
|
471 | 476 | |
472 | 477 | $this->parseStatusCode($rawMessage); |
473 | 478 | |
@@ -481,8 +486,9 @@ discard block |
||
481 | 486 | |
482 | 487 | $rawMessage = preg_split('/\r\n\r\n/', $rawMessage, 2); |
483 | 488 | |
484 | - if (empty($rawMessage)) |
|
485 | - throw new \RuntimeException("The server didn't return a valid Response for the Request."); |
|
489 | + if (empty($rawMessage)) { |
|
490 | + throw new \RuntimeException("The server didn't return a valid Response for the Request."); |
|
491 | + } |
|
486 | 492 | |
487 | 493 | // $rawMessage[0] contains header fields. |
488 | 494 | $this->parseHeaderFields($rawMessage[0]); |
@@ -508,9 +514,9 @@ discard block |
||
508 | 514 | public function setStatusCode($value) { |
509 | 515 | if (array_key_exists($value, self::$supportedStatusCodes)) { |
510 | 516 | $this->statusCode = $value; |
517 | + } else { |
|
518 | + throw new \UnexpectedValueException("Status Code $value is not supported."); |
|
511 | 519 | } |
512 | - else |
|
513 | - throw new \UnexpectedValueException("Status Code $value is not supported."); |
|
514 | 520 | } |
515 | 521 | |
516 | 522 | |
@@ -529,12 +535,13 @@ discard block |
||
529 | 535 | * @param string $description A description for the Status Code. |
530 | 536 | */ |
531 | 537 | public static function addCustomStatusCode($code, $description) { |
532 | - if (in_array($code, self::$supportedStatusCodes)) |
|
533 | - throw new \UnexpectedValueException("Status Code $code is supported and already exists."); |
|
534 | - elseif (is_int($code) and $code > 0) |
|
535 | - self::$supportedStatusCodes[$code] = $description; |
|
536 | - else |
|
537 | - throw new \InvalidArgumentException("\$code must be a positive integer."); |
|
538 | + if (in_array($code, self::$supportedStatusCodes)) { |
|
539 | + throw new \UnexpectedValueException("Status Code $code is supported and already exists."); |
|
540 | + } elseif (is_int($code) and $code > 0) { |
|
541 | + self::$supportedStatusCodes[$code] = $description; |
|
542 | + } else { |
|
543 | + throw new \InvalidArgumentException("\$code must be a positive integer."); |
|
544 | + } |
|
538 | 545 | } |
539 | 546 | |
540 | 547 | } |
541 | 548 | \ No newline at end of file |
@@ -205,8 +205,9 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function getHeaderAsArray() { |
207 | 207 | $wellformedHeader = []; |
208 | - foreach ($this->header as $name => $value) |
|
209 | - $wellformedHeader[] = $name.": ".$value; |
|
208 | + foreach ($this->header as $name => $value) { |
|
209 | + $wellformedHeader[] = $name.": ".$value; |
|
210 | + } |
|
210 | 211 | |
211 | 212 | return $wellformedHeader; |
212 | 213 | } |
@@ -237,10 +238,11 @@ discard block |
||
237 | 238 | * @return string |
238 | 239 | */ |
239 | 240 | public function getHeaderFieldValue($name) { |
240 | - if ($this->hasHeaderField($name)) |
|
241 | - return $this->header[$name]; |
|
242 | - else |
|
243 | - return FALSE; |
|
241 | + if ($this->hasHeaderField($name)) { |
|
242 | + return $this->header[$name]; |
|
243 | + } else { |
|
244 | + return FALSE; |
|
245 | + } |
|
244 | 246 | } |
245 | 247 | |
246 | 248 | |
@@ -250,10 +252,11 @@ discard block |
||
250 | 252 | * @param string $value The header field value. |
251 | 253 | */ |
252 | 254 | public function setHeaderField($name, $value) { |
253 | - if (array_key_exists($name, static::$supportedHeaderFields)) |
|
254 | - $this->header[$name] = $value; |
|
255 | - else |
|
256 | - throw new \Exception("$name header field is not supported."); |
|
255 | + if (array_key_exists($name, static::$supportedHeaderFields)) { |
|
256 | + $this->header[$name] = $value; |
|
257 | + } else { |
|
258 | + throw new \Exception("$name header field is not supported."); |
|
259 | + } |
|
257 | 260 | } |
258 | 261 | |
259 | 262 | |
@@ -262,8 +265,9 @@ discard block |
||
262 | 265 | * @param string $name The header field name. |
263 | 266 | */ |
264 | 267 | public function removeHeaderField($name) { |
265 | - if (array_key_exists($name, static::$supportedHeaderFields)) |
|
266 | - unset($this->header[$name]); |
|
268 | + if (array_key_exists($name, static::$supportedHeaderFields)) { |
|
269 | + unset($this->header[$name]); |
|
270 | + } |
|
267 | 271 | } |
268 | 272 | |
269 | 273 | |
@@ -272,11 +276,12 @@ discard block |
||
272 | 276 | * @param array $headerFields An associative array of header fields. |
273 | 277 | */ |
274 | 278 | public function setMultipleHeaderFieldsAtOnce(array $headerFields) { |
275 | - if (ArrayHelper::isAssociative($headerFields)) |
|
276 | - foreach ($headerFields as $name => $value) |
|
279 | + if (ArrayHelper::isAssociative($headerFields)) { |
|
280 | + foreach ($headerFields as $name => $value) |
|
277 | 281 | $this->setHeaderField($name, $value); |
278 | - else |
|
279 | - throw new \Exception("\$headerFields must be an associative array."); |
|
282 | + } else { |
|
283 | + throw new \Exception("\$headerFields must be an associative array."); |
|
284 | + } |
|
280 | 285 | } |
281 | 286 | |
282 | 287 | |
@@ -285,10 +290,11 @@ discard block |
||
285 | 290 | * @param string $name Header field name. |
286 | 291 | */ |
287 | 292 | public static function addCustomHeaderField($name) { |
288 | - if (array_key_exists($name, static::$supportedHeaderFields)) |
|
289 | - throw new \Exception("$name header field is supported but already exists."); |
|
290 | - else |
|
291 | - static::$supportedHeaderFields[] = $name; |
|
293 | + if (array_key_exists($name, static::$supportedHeaderFields)) { |
|
294 | + throw new \Exception("$name header field is supported but already exists."); |
|
295 | + } else { |
|
296 | + static::$supportedHeaderFields[] = $name; |
|
297 | + } |
|
292 | 298 | } |
293 | 299 | |
294 | 300 |
@@ -189,9 +189,9 @@ discard block |
||
189 | 189 | */ |
190 | 190 | const X_FORWARDED_FOR_HF = "X-Forwarded-For"; |
191 | 191 | |
192 | - const DESTINATION_HF = "Destination"; //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB. |
|
193 | - const X_COUCHDB_WWW_AUTHENTICATE_HF = "X-CouchDB-WWW-Authenticate"; //!< This header field is not supported by HTTP 1.1. It's a special method header field by CouchDB. |
|
194 | - const X_COUCHDB_FULL_COMMIT_HF = "X-Couch-Full-Commit"; //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB. |
|
192 | + const DESTINATION_HF = "Destination"; //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB. |
|
193 | + const X_COUCHDB_WWW_AUTHENTICATE_HF = "X-CouchDB-WWW-Authenticate"; //!< This header field is not supported by HTTP 1.1. It's a special method header field by CouchDB. |
|
194 | + const X_COUCHDB_FULL_COMMIT_HF = "X-Couch-Full-Commit"; //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB. |
|
195 | 195 | |
196 | 196 | //!@} |
197 | 197 | |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | $params = explode('&', $query); |
409 | 409 | |
410 | 410 | foreach ($params as $param) { |
411 | - @list($name, $value) = explode('=', $param, 2); |
|
411 | + @list($name, $value) = explode('=', $param, 2); |
|
412 | 412 | $this->setQueryParam($name, $value); |
413 | 413 | } |
414 | 414 | } |
@@ -281,11 +281,13 @@ discard block |
||
281 | 281 | $this->setMethod($method); |
282 | 282 | $this->setPath($path); |
283 | 283 | |
284 | - if (isset($queryParams)) |
|
285 | - $this->setMultipleQueryParamsAtOnce($queryParams); |
|
284 | + if (isset($queryParams)) { |
|
285 | + $this->setMultipleQueryParamsAtOnce($queryParams); |
|
286 | + } |
|
286 | 287 | |
287 | - if (isset($headerFields)) |
|
288 | - $this->setMultipleHeaderFieldsAtOnce($headerFields); |
|
288 | + if (isset($headerFields)) { |
|
289 | + $this->setMultipleHeaderFieldsAtOnce($headerFields); |
|
290 | + } |
|
289 | 291 | } |
290 | 292 | |
291 | 293 | |
@@ -318,10 +320,11 @@ discard block |
||
318 | 320 | * @param string $method The HTTP method for the request. You should use one of the public constants, like GET_METHOD. |
319 | 321 | */ |
320 | 322 | public function setMethod($method) { |
321 | - if (array_key_exists($method, self::$supportedMethods)) |
|
322 | - $this->method = $method; |
|
323 | - else |
|
324 | - throw new \UnexpectedValueException("$method method not supported. Use addCustomMethod() to add an unsupported method."); |
|
323 | + if (array_key_exists($method, self::$supportedMethods)) { |
|
324 | + $this->method = $method; |
|
325 | + } else { |
|
326 | + throw new \UnexpectedValueException("$method method not supported. Use addCustomMethod() to add an unsupported method."); |
|
327 | + } |
|
325 | 328 | } |
326 | 329 | |
327 | 330 | |
@@ -330,10 +333,11 @@ discard block |
||
330 | 333 | * @param string $method The HTTP custom method. |
331 | 334 | */ |
332 | 335 | public static function addCustomMethod($method) { |
333 | - if (array_key_exists($method, self::$supportedMethods)) |
|
334 | - throw new \UnexpectedValueException("$method method is supported and already exists."); |
|
335 | - else |
|
336 | - self::$supportedMethods[] = $method; |
|
336 | + if (array_key_exists($method, self::$supportedMethods)) { |
|
337 | + throw new \UnexpectedValueException("$method method is supported and already exists."); |
|
338 | + } else { |
|
339 | + self::$supportedMethods[] = $method; |
|
340 | + } |
|
337 | 341 | } |
338 | 342 | |
339 | 343 | |
@@ -351,10 +355,11 @@ discard block |
||
351 | 355 | * @param string $path The absolute path of the request. |
352 | 356 | */ |
353 | 357 | public function setPath($path) { |
354 | - if (is_string($path)) |
|
355 | - $this->path = addslashes($path); |
|
356 | - else |
|
357 | - throw new \InvalidArgumentException("\$path must be a string."); |
|
358 | + if (is_string($path)) { |
|
359 | + $this->path = addslashes($path); |
|
360 | + } else { |
|
361 | + throw new \InvalidArgumentException("\$path must be a string."); |
|
362 | + } |
|
358 | 363 | } |
359 | 364 | |
360 | 365 | |
@@ -364,11 +369,12 @@ discard block |
||
364 | 369 | * @param string $value Parameter value. |
365 | 370 | */ |
366 | 371 | public function setQueryParam($name, $value) { |
367 | - if (preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $name)) |
|
368 | - $this->queryParams[$name] = $value; |
|
369 | - else |
|
370 | - throw new \InvalidArgumentException("\$name must start with a letter or underscore, followed by any number of |
|
372 | + if (preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $name)) { |
|
373 | + $this->queryParams[$name] = $value; |
|
374 | + } else { |
|
375 | + throw new \InvalidArgumentException("\$name must start with a letter or underscore, followed by any number of |
|
371 | 376 | letters, numbers, or underscores."); |
377 | + } |
|
372 | 378 | } |
373 | 379 | |
374 | 380 | |
@@ -377,11 +383,12 @@ discard block |
||
377 | 383 | * @param array $params An associative array of parameters. |
378 | 384 | */ |
379 | 385 | public function setMultipleQueryParamsAtOnce(array $params) { |
380 | - if (ArrayHelper::isAssociative($params)) |
|
381 | - foreach ($params as $name => $value) |
|
386 | + if (ArrayHelper::isAssociative($params)) { |
|
387 | + foreach ($params as $name => $value) |
|
382 | 388 | $this->setQueryParam($name, $value); |
383 | - else |
|
384 | - throw new \InvalidArgumentException("\$params must be an associative array."); |
|
389 | + } else { |
|
390 | + throw new \InvalidArgumentException("\$params must be an associative array."); |
|
391 | + } |
|
385 | 392 | } |
386 | 393 | |
387 | 394 | |
@@ -390,11 +397,12 @@ discard block |
||
390 | 397 | * @retval string |
391 | 398 | */ |
392 | 399 | public function getQueryString() { |
393 | - if (empty($this->queryParams)) |
|
394 | - return ""; |
|
395 | - else |
|
396 | - // Encoding is based on RFC 3986. |
|
400 | + if (empty($this->queryParams)) { |
|
401 | + return ""; |
|
402 | + } else { |
|
403 | + // Encoding is based on RFC 3986. |
|
397 | 404 | return "?".http_build_query($this->queryParams, NULL, "&", PHP_QUERY_RFC3986); |
405 | + } |
|
398 | 406 | } |
399 | 407 | |
400 | 408 |
@@ -76,7 +76,7 @@ |
||
76 | 76 | if (preg_match(self::SCHEME_HOST_PORT_URI, $server, $matches)) { |
77 | 77 | $this->scheme = isset($matches['scheme']) ? $matches['scheme'] : "tcp://"; |
78 | 78 | $this->host = isset($matches['host']) ? $matches['host'] : self::DEFAULT_HOST; |
79 | - $this->port = isset($matches['port']) ? (int) substr($matches['port'], 1) : self::$defaultPorts[$this->scheme]; |
|
79 | + $this->port = isset($matches['port']) ? (int)substr($matches['port'], 1) : self::$defaultPorts[$this->scheme]; |
|
80 | 80 | } |
81 | 81 | else // Match attempt failed. |
82 | 82 | throw new \InvalidArgumentException(sprintf("'%s' is not a valid URI.", $server)); |
@@ -77,9 +77,10 @@ |
||
77 | 77 | $this->scheme = isset($matches['scheme']) ? $matches['scheme'] : "tcp://"; |
78 | 78 | $this->host = isset($matches['host']) ? $matches['host'] : self::DEFAULT_HOST; |
79 | 79 | $this->port = isset($matches['port']) ? (int) substr($matches['port'], 1) : self::$defaultPorts[$this->scheme]; |
80 | - } |
|
81 | - else // Match attempt failed. |
|
80 | + } else { |
|
81 | + // Match attempt failed. |
|
82 | 82 | throw new \InvalidArgumentException(sprintf("'%s' is not a valid URI.", $server)); |
83 | + } |
|
83 | 84 | |
84 | 85 | $this->userName = (string)$userName; |
85 | 86 | $this->password = (string)$password; |
@@ -55,8 +55,9 @@ discard block |
||
55 | 55 | * @copydoc AbstractAdapter::initialize() |
56 | 56 | */ |
57 | 57 | public function initialize() { |
58 | - if (!extension_loaded("curl")) |
|
59 | - throw new \RuntimeException("The cURL extension is not loaded."); |
|
58 | + if (!extension_loaded("curl")) { |
|
59 | + throw new \RuntimeException("The cURL extension is not loaded."); |
|
60 | + } |
|
60 | 61 | } |
61 | 62 | |
62 | 63 | |
@@ -76,8 +77,9 @@ discard block |
||
76 | 77 | $opts = []; |
77 | 78 | |
78 | 79 | // Resets all the cURL options. The curl_reset() function is available only since PHP 5.5. |
79 | - if (function_exists('curl_reset')) |
|
80 | - curl_reset($this->handle); |
|
80 | + if (function_exists('curl_reset')) { |
|
81 | + curl_reset($this->handle); |
|
82 | + } |
|
81 | 83 | |
82 | 84 | // Sets the methods and its related options. |
83 | 85 | switch ($request->getMethod()) { |
@@ -112,9 +114,9 @@ discard block |
||
112 | 114 | |
113 | 115 | $opts[CURLOPT_INFILE] = $fd; |
114 | 116 | $opts[CURLOPT_INFILESIZE] = $request->getBodyLength(); |
117 | + } else { |
|
118 | + throw new \RuntimeException("Cannot create the stream."); |
|
115 | 119 | } |
116 | - else |
|
117 | - throw new \RuntimeException("Cannot create the stream."); |
|
118 | 120 | } |
119 | 121 | |
120 | 122 | break; |
@@ -155,8 +157,9 @@ discard block |
||
155 | 157 | // This fix a known cURL bug: see http://the-stickman.com/web-development/php-and-curl-disabling-100-continue-header/ |
156 | 158 | // cURL sets the Expect header field automatically, ignoring the fact that a client may not need it for the specific |
157 | 159 | // request. |
158 | - if (!$request->hasHeaderField(Request::EXPECT_HF)) |
|
159 | - curl_setopt($this->handle, CURLOPT_HTTPHEADER, array("Expect:")); |
|
160 | + if (!$request->hasHeaderField(Request::EXPECT_HF)) { |
|
161 | + curl_setopt($this->handle, CURLOPT_HTTPHEADER, array("Expect:")); |
|
162 | + } |
|
160 | 163 | |
161 | 164 | // Sets the request header. |
162 | 165 | // Due to a stupid bug, using curl_setopt_array(), cURL doesn't override the Content-Type header field. So we must |
@@ -184,15 +187,15 @@ discard block |
||
184 | 187 | }); |
185 | 188 | } |
186 | 189 | |
187 | - if ($this->timeout) |
|
188 | - curl_setopt($this->handle, CURLOPT_TIMEOUT, $this->timeout); |
|
190 | + if ($this->timeout) { |
|
191 | + curl_setopt($this->handle, CURLOPT_TIMEOUT, $this->timeout); |
|
192 | + } |
|
189 | 193 | |
190 | 194 | if ($result = curl_exec($this->handle)) { |
191 | 195 | $response = new Response($header); |
192 | 196 | $response->setBody($result); |
193 | 197 | return $response; |
194 | - } |
|
195 | - else { |
|
198 | + } else { |
|
196 | 199 | $error = curl_error($this->handle); |
197 | 200 | throw new \RuntimeException($error); |
198 | 201 | } |