Skip to content

Commit

Permalink
Add psr/http-interface v2 compatible return types to SwaggerRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
M1ke committed Apr 15, 2024
1 parent a87e476 commit 097ad11
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/Requests/SwaggerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SwaggerRequest implements RequestInterface {
*
* @return string HTTP protocol version.
*/
public function getProtocolVersion(){
public function getProtocolVersion() :string{
return '1.1';
}

Expand All @@ -48,7 +48,7 @@ public function getProtocolVersion(){
* @param string $version HTTP protocol version
* @return static
*/
public function withProtocolVersion(string $version){
public function withProtocolVersion(string $version) :self{
return clone $this;
}

Expand Down Expand Up @@ -77,7 +77,7 @@ public function withProtocolVersion(string $version){
* key MUST be a header name, and each value MUST be an array of strings
* for that header.
*/
public function getHeaders(){
public function getHeaders() :array{
return $this->headers;
}

Expand All @@ -89,7 +89,7 @@ public function getHeaders(){
* name using a case-insensitive string comparison. Returns false if
* no matching header name is found in the message.
*/
public function hasHeader($name){
public function hasHeader($name) :bool{
return isset($this->headers[$name]);
}

Expand All @@ -107,7 +107,7 @@ public function hasHeader($name){
* header. If the header does not appear in the message, this method MUST
* return an empty array.
*/
public function getHeader($name){
public function getHeader($name) :array{
return $this->headers[$name] ?: [];
}

Expand All @@ -130,7 +130,7 @@ public function getHeader($name){
* concatenated together using a comma. If the header does not appear in
* the message, this method MUST return an empty string.
*/
public function getHeaderLine($name){
public function getHeaderLine($name) :string{
return implode(',', $this->headers[$name] ?: []);
}

Expand All @@ -149,7 +149,7 @@ public function getHeaderLine($name){
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withHeader($name, $value){
public function withHeader($name, $value) :self{
$cloned = clone $this;
$cloned->setHeader($name, $value);

Expand Down Expand Up @@ -180,7 +180,7 @@ private function setHeader($name, $value){
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withAddedHeader($name, $value){
public function withAddedHeader($name, $value) :self{
$cloned = clone $this;
$cloned->addHeader($name, $value);

Expand Down Expand Up @@ -210,7 +210,7 @@ private function addHeader($name, $value){
* @param string $name Case-insensitive header field name to remove.
* @return static
*/
public function withoutHeader($name){
public function withoutHeader($name) :self{
return clone $this;
}

Expand All @@ -219,7 +219,7 @@ public function withoutHeader($name){
*
* @return StreamInterface Returns the body as a stream.
*/
public function getBody(){
public function getBody() :StreamInterface{
return $this->body;
}

Expand All @@ -236,7 +236,7 @@ public function getBody(){
* @return static
* @throws \InvalidArgumentException When the body is not valid.
*/
public function withBody(StreamInterface $body){
public function withBody(StreamInterface $body) :self{
return clone $this;
}

Expand All @@ -256,7 +256,7 @@ public function withBody(StreamInterface $body){
*
* @return string
*/
public function getRequestTarget(){
public function getRequestTarget() :string{
return (string)$this->getUri();
}

Expand All @@ -277,7 +277,7 @@ public function getRequestTarget(){
* @param mixed $requestTarget
* @return static
*/
public function withRequestTarget($requestTarget){
public function withRequestTarget($requestTarget) :self{
return clone $this;
}

Expand All @@ -286,7 +286,7 @@ public function withRequestTarget($requestTarget){
*
* @return string Returns the request method.
*/
public function getMethod(){
public function getMethod() :string{
return static::METHOD;
}

Expand All @@ -305,7 +305,7 @@ public function getMethod(){
* @return static
* @throws \InvalidArgumentException for invalid HTTP methods.
*/
public function withMethod($method){
public function withMethod($method) :self{
return clone $this;
}

Expand All @@ -318,7 +318,7 @@ public function withMethod($method){
* @return UriInterface Returns a UriInterface instance
* representing the URI of the request.
*/
public function getUri(){
public function getUri() :UriInterface{
if (is_null($this->uri)){
$this->uri = $this->makeUri();
}
Expand Down Expand Up @@ -356,7 +356,7 @@ public function getUri(){
* @param bool $preserveHost Preserve the original state of the Host header.
* @return static
*/
public function withUri(UriInterface $uri, $preserveHost = false){
public function withUri(UriInterface $uri, $preserveHost = false) :self{
$request = clone $this;
$request->setUri($uri);

Expand Down Expand Up @@ -405,7 +405,7 @@ public function __construct($uri){
* @see https://tools.ietf.org/html/rfc3986#section-3.1
* @return string The URI scheme.
*/
public function getScheme(){
public function getScheme(): string{
return $this->scheme;
}

Expand All @@ -427,7 +427,7 @@ public function getScheme(){
* @see https://tools.ietf.org/html/rfc3986#section-3.2
* @return string The URI authority, in "[user-info@]host[:port]" format.
*/
public function getAuthority(){
public function getAuthority() :string{
return '';
}

Expand All @@ -446,7 +446,7 @@ public function getAuthority(){
*
* @return string The URI user information, in "username[:password]" format.
*/
public function getUserInfo(){
public function getUserInfo(): string{
return '';
}

Expand All @@ -461,7 +461,7 @@ public function getUserInfo(){
* @see http://tools.ietf.org/html/rfc3986#section-3.2.2
* @return string The URI host.
*/
public function getHost(){
public function getHost(): string{
return explode('/', $this->uri)[0];
}

Expand All @@ -480,7 +480,7 @@ public function getHost(){
*
* @return null|int The URI port.
*/
public function getPort(){
public function getPort(): ?int{
return null;
}

Expand Down Expand Up @@ -509,13 +509,13 @@ public function getPort(){
* @see https://tools.ietf.org/html/rfc3986#section-3.3
* @return string The URI path.
*/
public function getPath(){
public function getPath(): string{
$no_host = $this->uriNoHost();

return explode('?', $no_host)[0];
}

private function uriNoHost(){
private function uriNoHost(): string{
$split = explode('/', $this->uri);
unset($split[0]);

Expand All @@ -542,7 +542,7 @@ private function uriNoHost(){
* @see https://tools.ietf.org/html/rfc3986#section-3.4
* @return string The URI query string.
*/
public function getQuery(){
public function getQuery(): string{
$no_host = $this->uriNoHost();

return explode('?', $no_host)[1] ?? '';
Expand All @@ -564,7 +564,7 @@ public function getQuery(){
* @see https://tools.ietf.org/html/rfc3986#section-3.5
* @return string The URI fragment.
*/
public function getFragment(){
public function getFragment(): string{
return '';
}

Expand All @@ -583,7 +583,7 @@ public function getFragment(){
* @return static A new instance with the specified scheme.
* @throws \InvalidArgumentException for invalid or unsupported schemes.
*/
public function withScheme($scheme){
public function withScheme($scheme) :UriInterface{
return clone $this;
}

Expand All @@ -601,7 +601,7 @@ public function withScheme($scheme){
* @param null|string $password The password associated with $user.
* @return static A new instance with the specified user information.
*/
public function withUserInfo($user, $password = null){
public function withUserInfo($user, $password = null): UriInterface{
return clone $this;
}

Expand All @@ -617,7 +617,7 @@ public function withUserInfo($user, $password = null){
* @return static A new instance with the specified host.
* @throws \InvalidArgumentException for invalid hostnames.
*/
public function withHost($host){
public function withHost($host): UriInterface{
$clone = clone $this;
$clone->setHost($host);

Expand Down Expand Up @@ -656,7 +656,7 @@ private function setHost($host){
* @return static A new instance with the specified port.
* @throws \InvalidArgumentException for invalid ports.
*/
public function withPort($port){
public function withPort($port): UriInterface{
return clone $this;
}

Expand All @@ -682,7 +682,7 @@ public function withPort($port){
* @return static A new instance with the specified path.
* @throws \InvalidArgumentException for invalid paths.
*/
public function withPath($path){
public function withPath($path): UriInterface{
return clone $this;
}

Expand All @@ -701,7 +701,7 @@ public function withPath($path){
* @return static A new instance with the specified query string.
* @throws \InvalidArgumentException for invalid query strings.
*/
public function withQuery($query){
public function withQuery($query): UriInterface{
$uri = clone $this;
$uri->setQuery($query);

Expand Down Expand Up @@ -735,7 +735,7 @@ private function setQuery($query){
* @param string $fragment The fragment to use with the new instance.
* @return static A new instance with the specified fragment.
*/
public function withFragment($fragment){
public function withFragment($fragment): UriInterface{
return clone $this;
}

Expand All @@ -762,7 +762,7 @@ public function withFragment($fragment){
* @see http://tools.ietf.org/html/rfc3986#section-4.1
* @return string
*/
public function __toString(){
public function __toString(): string{
return $this->getScheme().'://'.$this->uri;
}

Expand Down

0 comments on commit 097ad11

Please sign in to comment.