Skip to content

Commit

Permalink
Apply suggestions from Alain
Browse files Browse the repository at this point in the history
Co-Authored-By: Alain Schlesser <[email protected]>
  • Loading branch information
pierlon and schlessera committed Apr 2, 2020
1 parent a1203b5 commit e87ab88
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/RemoteRequest/CachedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ final class CachedResponse {
* Instantiate a CachedResponse object.
*
* @param string $body Cached body.
* @param array $headers Cached headers.
* @param string[] $headers Associative array of cached headers.
* @param int $status_code Cached status code.
* @param DateTimeInterface $expiry Expiry of the cached value.
*/
public function __construct( $body, array $headers, $status_code, DateTimeInterface $expiry ) {
$this->body = $body;
$this->headers = $headers;
$this->status_code = $status_code;
public function __construct( $body, $headers, $status_code, DateTimeInterface $expiry ) {
$this->body = (string) $body;
$this->headers = (array) $headers;
$this->status_code = (int) $status_code;
$this->expiry = $expiry;
}

Expand All @@ -72,7 +72,7 @@ public function get_body() {
/**
* Get the cached headers.
*
* @return array Cached headers.
* @return string[] Cached headers.
*/
public function get_headers() {
return $this->headers;
Expand All @@ -90,11 +90,11 @@ public function get_status_code() {
/**
* Determine the validity of the cached response.
*
* @return bool Whether the cached response if valid.
* @return bool Whether the cached response is valid.
*/
public function is_valid() {
// $this->headers is typed so no need for sanity check.
return null !== $this->body && is_int( $this->status_code );
// Values are already typed, so we just control the status code for validity.
return $this->status_code > 100 && $this->status_code <= 599;
}

/**
Expand Down

0 comments on commit e87ab88

Please sign in to comment.