From 64e8642b9a68c58b217cb69536bb0df9b7dc726f Mon Sep 17 00:00:00 2001 From: Trevor North Date: Tue, 4 Dec 2018 17:03:03 +0000 Subject: [PATCH 1/2] Provide native return type hints for ServerRequest helpers --- src/ServerRequest.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ServerRequest.php b/src/ServerRequest.php index a47ab6d..7eebefd 100644 --- a/src/ServerRequest.php +++ b/src/ServerRequest.php @@ -762,7 +762,7 @@ public function withUri(UriInterface $uri, $preserveHost = false) * * @return string|null */ - public function getContentCharset() + public function getContentCharset(): ?string { $mediaTypeParams = $this->getMediaTypeParams(); @@ -780,7 +780,7 @@ public function getContentCharset() * * @return string|null The serverRequest content type, if known */ - public function getContentType() + public function getContentType(): ?string { $result = $this->serverRequest->getHeader('Content-Type'); return $result ? $result[0] : null; @@ -793,7 +793,7 @@ public function getContentType() * * @return int|null */ - public function getContentLength() + public function getContentLength(): ?int { $result = $this->serverRequest->getHeader('Content-Length'); return $result ? (int) $result[0] : null; @@ -828,7 +828,7 @@ public function getCookieParam($key, $default = null) * * @return string|null The serverRequest media type, minus content-type params */ - public function getMediaType() + public function getMediaType(): ?string { $contentType = $this->getContentType(); @@ -848,9 +848,9 @@ public function getMediaType() * * Note: This method is not part of the PSR-7 standard. * - * @return array + * @return mixed[] */ - public function getMediaTypeParams() + public function getMediaTypeParams(): array { $contentType = $this->getContentType(); $contentTypeParams = []; @@ -901,9 +901,9 @@ public function getParam($key, $default = null) * * Note: This method is not part of the PSR-7 standard. * - * @return array + * @return mixed[] */ - public function getParams() + public function getParams(): ?array { $params = $this->getQueryParams(); $postParams = $this->getParsedBody(); @@ -1003,7 +1003,7 @@ public function registerMediaTypeParser($mediaType, callable $callable) * * @return bool */ - public function isDelete() + public function isDelete(): bool { return $this->isMethod('DELETE'); } @@ -1015,7 +1015,7 @@ public function isDelete() * * @return bool */ - public function isGet() + public function isGet(): bool { return $this->isMethod('GET'); } @@ -1027,7 +1027,7 @@ public function isGet() * * @return bool */ - public function isHead() + public function isHead(): bool { return $this->isMethod('HEAD'); } @@ -1040,7 +1040,7 @@ public function isHead() * @param string $method HTTP method * @return bool */ - public function isMethod($method) + public function isMethod($method): bool { return $this->serverRequest->getMethod() === $method; } @@ -1052,7 +1052,7 @@ public function isMethod($method) * * @return bool */ - public function isOptions() + public function isOptions(): bool { return $this->isMethod('OPTIONS'); } @@ -1064,7 +1064,7 @@ public function isOptions() * * @return bool */ - public function isPatch() + public function isPatch(): bool { return $this->isMethod('PATCH'); } @@ -1076,7 +1076,7 @@ public function isPatch() * * @return bool */ - public function isPost() + public function isPost(): bool { return $this->isMethod('POST'); } @@ -1088,7 +1088,7 @@ public function isPost() * * @return bool */ - public function isPut() + public function isPut(): bool { return $this->isMethod('PUT'); } @@ -1100,7 +1100,7 @@ public function isPut() * * @return bool */ - public function isXhr() + public function isXhr(): bool { return $this->serverRequest->getHeaderLine('X-Requested-With') === 'XMLHttpRequest'; } From 5d45c06ff7528d47410ec7a30c8f2626a794fab0 Mon Sep 17 00:00:00 2001 From: Trevor North Date: Wed, 5 Dec 2018 13:16:10 +0000 Subject: [PATCH 2/2] ServerRequest getParams return is not optional --- src/ServerRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServerRequest.php b/src/ServerRequest.php index 7eebefd..fd31c5c 100644 --- a/src/ServerRequest.php +++ b/src/ServerRequest.php @@ -903,7 +903,7 @@ public function getParam($key, $default = null) * * @return mixed[] */ - public function getParams(): ?array + public function getParams(): array { $params = $this->getQueryParams(); $postParams = $this->getParsedBody();