@@ -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 | } |
@@ -36,8 +36,9 @@ discard block |
||
| 36 | 36 | * @attention Chainable. |
| 37 | 37 | */ |
| 38 | 38 | public function unsetOpt($name) { |
| 39 | - if (array_key_exists($name, $this->options)) |
|
| 40 | - unset($this->options['name']); |
|
| 39 | + if (array_key_exists($name, $this->options)) { |
|
| 40 | + unset($this->options['name']); |
|
| 41 | + } |
|
| 41 | 42 | |
| 42 | 43 | return $this; |
| 43 | 44 | } |
@@ -137,10 +138,11 @@ discard block |
||
| 137 | 138 | * @attention Chainable. |
| 138 | 139 | */ |
| 139 | 140 | public function setLimit($value) { |
| 140 | - if (is_int($value) && $value > 0) |
|
| 141 | - $this->options["limit"] = $value; |
|
| 142 | - else |
|
| 143 | - throw new \Exception("\$value must be a positive integer."); |
|
| 141 | + if (is_int($value) && $value > 0) { |
|
| 142 | + $this->options["limit"] = $value; |
|
| 143 | + } else { |
|
| 144 | + throw new \Exception("\$value must be a positive integer."); |
|
| 145 | + } |
|
| 144 | 146 | |
| 145 | 147 | return $this; |
| 146 | 148 | } |
@@ -173,9 +175,9 @@ discard block |
||
| 173 | 175 | if (is_int($value) && $value > 0) { |
| 174 | 176 | $this->options["group"] = "false"; // This parameter is used only if 'group' is 'false'. |
| 175 | 177 | $this->options["group_level"] = $value; |
| 178 | + } else { |
|
| 179 | + throw new \Exception("\$value must be a positive integer."); |
|
| 176 | 180 | } |
| 177 | - else |
|
| 178 | - throw new \Exception("\$value must be a positive integer."); |
|
| 179 | 181 | |
| 180 | 182 | return $this; |
| 181 | 183 | } |
@@ -310,10 +312,11 @@ discard block |
||
| 310 | 312 | * @attention Chainable. |
| 311 | 313 | */ |
| 312 | 314 | public function skipDocs($number) { |
| 313 | - if (is_int($number) && $number > 0) |
|
| 314 | - $this->options["skip"] = $number; |
|
| 315 | - else |
|
| 316 | - throw new \Exception("\$number must be a positive integer."); |
|
| 315 | + if (is_int($number) && $number > 0) { |
|
| 316 | + $this->options["skip"] = $number; |
|
| 317 | + } else { |
|
| 318 | + throw new \Exception("\$number must be a positive integer."); |
|
| 319 | + } |
|
| 317 | 320 | |
| 318 | 321 | return $this; |
| 319 | 322 | } |
@@ -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 | } |
@@ -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[in] 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[in] 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[in] 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[in] 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[in] array $params An associative array of parameters. |
| 378 | 384 | */ |
| 379 | 385 | public function setMultipleQueryParamsAtOnce(array $params) { |
| 380 | - if (Helper\ArrayHelper::isAssociative($params)) |
|
| 381 | - foreach ($params as $name => $value) |
|
| 386 | + if (Helper\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 | |
@@ -417,13 +417,15 @@ discard block |
||
| 417 | 417 | |
| 418 | 418 | protected function parseStatusCode($rawMessage) { |
| 419 | 419 | $matches = []; |
| 420 | - if (preg_match('%HTTP/1\.[0-1] (\d\d\d) %', $rawMessage, $matches)) |
|
| 421 | - $this->statusCode = $matches[1]; |
|
| 422 | - else |
|
| 423 | - throw new \UnexpectedValueException("HTTP Status Code undefined."); |
|
| 420 | + if (preg_match('%HTTP/1\.[0-1] (\d\d\d) %', $rawMessage, $matches)) { |
|
| 421 | + $this->statusCode = $matches[1]; |
|
| 422 | + } else { |
|
| 423 | + throw new \UnexpectedValueException("HTTP Status Code undefined."); |
|
| 424 | + } |
|
| 424 | 425 | |
| 425 | - if (!array_key_exists($this->statusCode, self::$supportedStatusCodes)) |
|
| 426 | - throw new \UnexpectedValueException("HTTP Status Code unknown."); |
|
| 426 | + if (!array_key_exists($this->statusCode, self::$supportedStatusCodes)) { |
|
| 427 | + throw new \UnexpectedValueException("HTTP Status Code unknown."); |
|
| 428 | + } |
|
| 427 | 429 | } |
| 428 | 430 | |
| 429 | 431 | |
@@ -439,21 +441,24 @@ discard block |
||
| 439 | 441 | }, |
| 440 | 442 | strtolower(trim($matches[1]))); |
| 441 | 443 | |
| 442 | - if (isset($this->header[$matches[1]])) |
|
| 443 | - $this->header[$matches[1]] = array($this->header[$matches[1]], $matches[2]); |
|
| 444 | - else |
|
| 445 | - $this->header[$matches[1]] = trim($matches[2]); |
|
| 444 | + if (isset($this->header[$matches[1]])) { |
|
| 445 | + $this->header[$matches[1]] = array($this->header[$matches[1]], $matches[2]); |
|
| 446 | + } else { |
|
| 447 | + $this->header[$matches[1]] = trim($matches[2]); |
|
| 448 | + } |
|
| 446 | 449 | } |
| 447 | 450 | } |
| 448 | 451 | } |
| 449 | 452 | |
| 450 | 453 | |
| 451 | 454 | protected function parseStatusCodeAndHeader($rawMessage) { |
| 452 | - if (!is_string($rawMessage)) |
|
| 453 | - throw new \InvalidArgumentException("\$rawMessage must be a string."); |
|
| 455 | + if (!is_string($rawMessage)) { |
|
| 456 | + throw new \InvalidArgumentException("\$rawMessage must be a string."); |
|
| 457 | + } |
|
| 454 | 458 | |
| 455 | - if (empty($rawMessage)) |
|
| 456 | - throw new \UnexpectedValueException("\$rawMessage is null."); |
|
| 459 | + if (empty($rawMessage)) { |
|
| 460 | + throw new \UnexpectedValueException("\$rawMessage is null."); |
|
| 461 | + } |
|
| 457 | 462 | |
| 458 | 463 | $this->parseStatusCode($rawMessage); |
| 459 | 464 | |
@@ -467,8 +472,9 @@ discard block |
||
| 467 | 472 | |
| 468 | 473 | $rawMessage = preg_split('/\r\n\r\n/', $rawMessage, 2); |
| 469 | 474 | |
| 470 | - if (empty($rawMessage)) |
|
| 471 | - throw new \RuntimeException("The server didn't return a valid Response for the Request."); |
|
| 475 | + if (empty($rawMessage)) { |
|
| 476 | + throw new \RuntimeException("The server didn't return a valid Response for the Request."); |
|
| 477 | + } |
|
| 472 | 478 | |
| 473 | 479 | // $rawMessage[0] contains header fields. |
| 474 | 480 | $this->parseHeaderFields($rawMessage[0]); |
@@ -494,9 +500,9 @@ discard block |
||
| 494 | 500 | public function setStatusCode($value) { |
| 495 | 501 | if (array_key_exists($value, self::$supportedStatusCodes)) { |
| 496 | 502 | $this->statusCode = $value; |
| 503 | + } else { |
|
| 504 | + throw new \UnexpectedValueException("Status Code $value is not supported."); |
|
| 497 | 505 | } |
| 498 | - else |
|
| 499 | - throw new \UnexpectedValueException("Status Code $value is not supported."); |
|
| 500 | 506 | } |
| 501 | 507 | |
| 502 | 508 | |
@@ -515,12 +521,13 @@ discard block |
||
| 515 | 521 | * @param[in] string $description A description for the Status Code. |
| 516 | 522 | */ |
| 517 | 523 | public static function addCustomStatusCode($code, $description) { |
| 518 | - if (in_array($code, self::$supportedStatusCodes)) |
|
| 519 | - throw new \UnexpectedValueException("Status Code $code is supported and already exists."); |
|
| 520 | - elseif (is_int($code) and $code > 0) |
|
| 521 | - self::$supportedStatusCodes[$code] = $description; |
|
| 522 | - else |
|
| 523 | - throw new \InvalidArgumentException("\$code must be a positive integer."); |
|
| 524 | + if (in_array($code, self::$supportedStatusCodes)) { |
|
| 525 | + throw new \UnexpectedValueException("Status Code $code is supported and already exists."); |
|
| 526 | + } elseif (is_int($code) and $code > 0) { |
|
| 527 | + self::$supportedStatusCodes[$code] = $description; |
|
| 528 | + } else { |
|
| 529 | + throw new \InvalidArgumentException("\$code must be a positive integer."); |
|
| 530 | + } |
|
| 524 | 531 | } |
| 525 | 532 | |
| 526 | 533 | } |
| 527 | 534 | \ No newline at end of file |
@@ -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 | |
@@ -18,31 +18,35 @@ |
||
| 18 | 18 | trait TProperty { |
| 19 | 19 | |
| 20 | 20 | public function __get($name) { |
| 21 | - if (method_exists($this, ($method = 'get'.ucfirst($name)))) |
|
| 22 | - return $this->$method(); |
|
| 23 | - else |
|
| 24 | - throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 21 | + if (method_exists($this, ($method = 'get'.ucfirst($name)))) { |
|
| 22 | + return $this->$method(); |
|
| 23 | + } else { |
|
| 24 | + throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 25 | + } |
|
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | public function __isset($name) { |
| 28 | - if (method_exists($this, ($method = 'isset'.ucfirst($name)))) |
|
| 29 | - return $this->$method(); |
|
| 30 | - else |
|
| 31 | - throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 29 | + if (method_exists($this, ($method = 'isset'.ucfirst($name)))) { |
|
| 30 | + return $this->$method(); |
|
| 31 | + } else { |
|
| 32 | + throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 33 | + } |
|
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | public function __set($name, $value) { |
| 35 | - if (method_exists($this, ($method = 'set'.ucfirst($name)))) |
|
| 36 | - $this->$method($value); |
|
| 37 | - else |
|
| 38 | - throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 37 | + if (method_exists($this, ($method = 'set'.ucfirst($name)))) { |
|
| 38 | + $this->$method($value); |
|
| 39 | + } else { |
|
| 40 | + throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 41 | + } |
|
| 39 | 42 | } |
| 40 | 43 | |
| 41 | 44 | public function __unset($name) { |
| 42 | - if (method_exists($this, ($method = 'unset'.ucfirst($name)))) |
|
| 43 | - $this->$method(); |
|
| 44 | - else |
|
| 45 | - throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 45 | + if (method_exists($this, ($method = 'unset'.ucfirst($name)))) { |
|
| 46 | + $this->$method(); |
|
| 47 | + } else { |
|
| 48 | + throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 49 | + } |
|
| 46 | 50 | } |
| 47 | 51 | |
| 48 | 52 | } |
| 49 | 53 | \ No newline at end of file |
@@ -59,10 +59,11 @@ |
||
| 59 | 59 | public static function fromJson($json, $assoc) { |
| 60 | 60 | $data = json_decode((string)$json, $assoc); |
| 61 | 61 | |
| 62 | - if (is_null($data)) |
|
| 63 | - switch (json_last_error()) { |
|
| 62 | + if (is_null($data)) { |
|
| 63 | + switch (json_last_error()) { |
|
| 64 | 64 | case JSON_ERROR_DEPTH: |
| 65 | 65 | throw new JSONErrorException("Unable to parse the given JSON, the maximum stack depth has been exceeded."); |
| 66 | + } |
|
| 66 | 67 | break; |
| 67 | 68 | case JSON_ERROR_STATE_MISMATCH: |
| 68 | 69 | throw new JSONErrorException("Unable to parse the given JSON, invalid or malformed JSON."); |