diff options
Diffstat (limited to 'guzzlehttp/psr7/src/Request.php')
-rw-r--r-- | guzzlehttp/psr7/src/Request.php | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/guzzlehttp/psr7/src/Request.php b/guzzlehttp/psr7/src/Request.php index c1cdaebf..b17af66a 100644 --- a/guzzlehttp/psr7/src/Request.php +++ b/guzzlehttp/psr7/src/Request.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace GuzzleHttp\Psr7; use InvalidArgumentException; @@ -26,16 +28,16 @@ class Request implements RequestInterface /** * @param string $method HTTP method * @param string|UriInterface $uri URI - * @param array $headers Request headers + * @param array<string, string|string[]> $headers Request headers * @param string|resource|StreamInterface|null $body Request body * @param string $version Protocol version */ public function __construct( - $method, + string $method, $uri, array $headers = [], $body = null, - $version = '1.1' + string $version = '1.1' ) { $this->assertMethod($method); if (!($uri instanceof UriInterface)) { @@ -56,14 +58,14 @@ class Request implements RequestInterface } } - public function getRequestTarget() + public function getRequestTarget(): string { if ($this->requestTarget !== null) { return $this->requestTarget; } $target = $this->uri->getPath(); - if ($target == '') { + if ($target === '') { $target = '/'; } if ($this->uri->getQuery() != '') { @@ -73,7 +75,7 @@ class Request implements RequestInterface return $target; } - public function withRequestTarget($requestTarget) + public function withRequestTarget($requestTarget): RequestInterface { if (preg_match('#\s#', $requestTarget)) { throw new InvalidArgumentException( @@ -86,12 +88,12 @@ class Request implements RequestInterface return $new; } - public function getMethod() + public function getMethod(): string { return $this->method; } - public function withMethod($method) + public function withMethod($method): RequestInterface { $this->assertMethod($method); $new = clone $this; @@ -99,12 +101,12 @@ class Request implements RequestInterface return $new; } - public function getUri() + public function getUri(): UriInterface { return $this->uri; } - public function withUri(UriInterface $uri, $preserveHost = false) + public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface { if ($uri === $this->uri) { return $this; @@ -120,7 +122,7 @@ class Request implements RequestInterface return $new; } - private function updateHostFromUri() + private function updateHostFromUri(): void { $host = $this->uri->getHost(); @@ -143,10 +145,13 @@ class Request implements RequestInterface $this->headers = [$header => [$host]] + $this->headers; } - private function assertMethod($method) + /** + * @param mixed $method + */ + private function assertMethod($method): void { if (!is_string($method) || $method === '') { - throw new \InvalidArgumentException('Method must be a non-empty string.'); + throw new InvalidArgumentException('Method must be a non-empty string.'); } } } |