@@ -49,19 +49,22 @@ discard block |
||
49 | 49 | |
50 | 50 | |
51 | 51 | public function setMetadata($name, $value, $override = TRUE, $allowNull = TRUE) { |
52 | - if (is_null($value) && !$allowNull) |
|
53 | - return; |
|
52 | + if (is_null($value) && !$allowNull) { |
|
53 | + return; |
|
54 | + } |
|
54 | 55 | |
55 | - if ($this->isMetadataPresent($name) && !$override) |
|
56 | - return; |
|
56 | + if ($this->isMetadataPresent($name) && !$override) { |
|
57 | + return; |
|
58 | + } |
|
57 | 59 | |
58 | 60 | $this->meta[$name] = $value; |
59 | 61 | } |
60 | 62 | |
61 | 63 | |
62 | 64 | public function unsetMetadata($name) { |
63 | - if (array_key_exists($name, $this->meta)) |
|
64 | - unset($this->meta[$name]); |
|
65 | + if (array_key_exists($name, $this->meta)) { |
|
66 | + unset($this->meta[$name]); |
|
67 | + } |
|
65 | 68 | } |
66 | 69 | |
67 | 70 | |
@@ -95,9 +98,9 @@ discard block |
||
95 | 98 | if (Helper\ArrayHelper::isAssociative($array)) { |
96 | 99 | $this->meta = array_merge($this->meta, $array); |
97 | 100 | $this->fixDocId(); |
101 | + } else { |
|
102 | + throw new \InvalidArgumentException("\$array must be an associative array."); |
|
98 | 103 | } |
99 | - else |
|
100 | - throw new \InvalidArgumentException("\$array must be an associative array."); |
|
101 | 104 | } |
102 | 105 | |
103 | 106 | |
@@ -114,8 +117,9 @@ discard block |
||
114 | 117 | JSON_PRESERVE_ZERO_FRACTION |
115 | 118 | ); |
116 | 119 | |
117 | - if ($json === FALSE) |
|
118 | - throw new JSONErrorException(json_last_error_msg()); |
|
120 | + if ($json === FALSE) { |
|
121 | + throw new JSONErrorException(json_last_error_msg()); |
|
122 | + } |
|
119 | 123 | |
120 | 124 | return $json; |
121 | 125 | } |
@@ -157,8 +161,9 @@ discard block |
||
157 | 161 | |
158 | 162 | |
159 | 163 | public function unsetId() { |
160 | - if ($this->isMetadataPresent('_id')) |
|
161 | - unset($this->meta['_id']); |
|
164 | + if ($this->isMetadataPresent('_id')) { |
|
165 | + unset($this->meta['_id']); |
|
166 | + } |
|
162 | 167 | } |
163 | 168 | |
164 | 169 | |
@@ -178,8 +183,9 @@ discard block |
||
178 | 183 | |
179 | 184 | |
180 | 185 | public function unsetRev() { |
181 | - if ($this->isMetadataPresent('_rev')) |
|
182 | - unset($this->meta['_rev']); |
|
186 | + if ($this->isMetadataPresent('_rev')) { |
|
187 | + unset($this->meta['_rev']); |
|
188 | + } |
|
183 | 189 | } |
184 | 190 | |
185 | 191 | } |
186 | 192 | \ No newline at end of file |
@@ -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[in] 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[in] 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 |