@@ -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 |