Skip to content

Commit

Permalink
Merge pull request #95 from Stilch/add-param-and-return-type-hints
Browse files Browse the repository at this point in the history
Add return typehints

Since [psr/http-message version 2.0](https://packagist.org/packages/psr/http-message#2.0.0), the above interfaces have been updated to add return type declarations.
https://www.php-fig.org/psr/psr-7/meta/
  • Loading branch information
vdelau authored Apr 4, 2023
2 parents cb6ce48 + 947607b commit 402d35b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 82 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
"homepage": "https://www.php-fig.org/"
}
],
"require": {
Expand All @@ -20,7 +20,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
"dev-master": "2.0.x-dev"
}
}
}
24 changes: 11 additions & 13 deletions src/MessageInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

namespace Psr\Http\Message;

/**
Expand All @@ -25,7 +23,7 @@ interface MessageInterface
*
* @return string HTTP protocol version.
*/
public function getProtocolVersion();
public function getProtocolVersion(): string;

/**
* Return an instance with the specified HTTP protocol version.
Expand All @@ -40,7 +38,7 @@ public function getProtocolVersion();
* @param string $version HTTP protocol version
* @return static
*/
public function withProtocolVersion(string $version);
public function withProtocolVersion(string $version): MessageInterface;

/**
* Retrieves all message header values.
Expand All @@ -67,7 +65,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;

/**
* Checks if a header exists by the given case-insensitive name.
Expand All @@ -77,7 +75,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(string $name);
public function hasHeader(string $name): bool;

/**
* Retrieves a message header value by the given case-insensitive name.
Expand All @@ -93,7 +91,7 @@ public function hasHeader(string $name);
* header. If the header does not appear in the message, this method MUST
* return an empty array.
*/
public function getHeader(string $name);
public function getHeader(string $name): array;

/**
* Retrieves a comma-separated string of the values for a single header.
Expand All @@ -114,7 +112,7 @@ public function getHeader(string $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(string $name);
public function getHeaderLine(string $name): string;

/**
* Return an instance with the provided value replacing the specified header.
Expand All @@ -131,7 +129,7 @@ public function getHeaderLine(string $name);
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withHeader(string $name, $value);
public function withHeader(string $name, $value): MessageInterface;

/**
* Return an instance with the specified header appended with the given value.
Expand All @@ -149,7 +147,7 @@ public function withHeader(string $name, $value);
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withAddedHeader(string $name, $value);
public function withAddedHeader(string $name, $value): MessageInterface;

/**
* Return an instance without the specified header.
Expand All @@ -163,14 +161,14 @@ public function withAddedHeader(string $name, $value);
* @param string $name Case-insensitive header field name to remove.
* @return static
*/
public function withoutHeader(string $name);
public function withoutHeader(string $name): MessageInterface;

/**
* Gets the body of the message.
*
* @return StreamInterface Returns the body as a stream.
*/
public function getBody();
public function getBody(): StreamInterface;

/**
* Return an instance with the specified message body.
Expand All @@ -185,5 +183,5 @@ public function getBody();
* @return static
* @throws \InvalidArgumentException When the body is not valid.
*/
public function withBody(StreamInterface $body);
public function withBody(StreamInterface $body): MessageInterface;
}
15 changes: 7 additions & 8 deletions src/RequestInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

namespace Psr\Http\Message;

/**
Expand Down Expand Up @@ -41,7 +39,7 @@ interface RequestInterface extends MessageInterface
*
* @return string
*/
public function getRequestTarget();
public function getRequestTarget(): string;

/**
* Return an instance with the specific request-target.
Expand All @@ -60,14 +58,15 @@ public function getRequestTarget();
* @param string $requestTarget
* @return static
*/
public function withRequestTarget(string $requestTarget);
public function withRequestTarget(string $requestTarget): RequestInterface;


/**
* Retrieves the HTTP method of the request.
*
* @return string Returns the request method.
*/
public function getMethod();
public function getMethod(): string;

/**
* Return an instance with the provided HTTP method.
Expand All @@ -84,7 +83,7 @@ public function getMethod();
* @return static
* @throws \InvalidArgumentException for invalid HTTP methods.
*/
public function withMethod(string $method);
public function withMethod(string $method): RequestInterface;

/**
* Retrieves the URI instance.
Expand All @@ -95,7 +94,7 @@ public function withMethod(string $method);
* @return UriInterface Returns a UriInterface instance
* representing the URI of the request.
*/
public function getUri();
public function getUri(): UriInterface;

/**
* Returns an instance with the provided URI.
Expand Down Expand Up @@ -127,5 +126,5 @@ public function getUri();
* @param bool $preserveHost Preserve the original state of the Host header.
* @return static
*/
public function withUri(UriInterface $uri, bool $preserveHost = false);
public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface;
}
8 changes: 3 additions & 5 deletions src/ResponseInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

namespace Psr\Http\Message;

/**
Expand Down Expand Up @@ -29,7 +27,7 @@ interface ResponseInterface extends MessageInterface
*
* @return int Status code.
*/
public function getStatusCode();
public function getStatusCode(): int;

/**
* Return an instance with the specified status code and, optionally, reason phrase.
Expand All @@ -51,7 +49,7 @@ public function getStatusCode();
* @return static
* @throws \InvalidArgumentException For invalid status code arguments.
*/
public function withStatus(int $code, string $reasonPhrase = '');
public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface;

/**
* Gets the response reason phrase associated with the status code.
Expand All @@ -66,5 +64,5 @@ public function withStatus(int $code, string $reasonPhrase = '');
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
* @return string Reason phrase; must return an empty string if none present.
*/
public function getReasonPhrase();
public function getReasonPhrase(): string;
}
24 changes: 11 additions & 13 deletions src/ServerRequestInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

namespace Psr\Http\Message;

/**
Expand Down Expand Up @@ -53,7 +51,7 @@ interface ServerRequestInterface extends RequestInterface
*
* @return array
*/
public function getServerParams();
public function getServerParams(): array;

/**
* Retrieve cookies.
Expand All @@ -65,7 +63,7 @@ public function getServerParams();
*
* @return array
*/
public function getCookieParams();
public function getCookieParams(): array;

/**
* Return an instance with the specified cookies.
Expand All @@ -84,7 +82,7 @@ public function getCookieParams();
* @param array $cookies Array of key/value pairs representing cookies.
* @return static
*/
public function withCookieParams(array $cookies);
public function withCookieParams(array $cookies): ServerRequestInterface;

/**
* Retrieve query string arguments.
Expand All @@ -98,7 +96,7 @@ public function withCookieParams(array $cookies);
*
* @return array
*/
public function getQueryParams();
public function getQueryParams(): array;

/**
* Return an instance with the specified query string arguments.
Expand All @@ -122,7 +120,7 @@ public function getQueryParams();
* $_GET.
* @return static
*/
public function withQueryParams(array $query);
public function withQueryParams(array $query): ServerRequestInterface;

/**
* Retrieve normalized file upload data.
Expand All @@ -136,7 +134,7 @@ public function withQueryParams(array $query);
* @return array An array tree of UploadedFileInterface instances; an empty
* array MUST be returned if no data is present.
*/
public function getUploadedFiles();
public function getUploadedFiles(): array;

/**
* Create a new instance with the specified uploaded files.
Expand All @@ -149,7 +147,7 @@ public function getUploadedFiles();
* @return static
* @throws \InvalidArgumentException if an invalid structure is provided.
*/
public function withUploadedFiles(array $uploadedFiles);
public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface;

/**
* Retrieve any parameters provided in the request body.
Expand Down Expand Up @@ -196,7 +194,7 @@ public function getParsedBody();
* @throws \InvalidArgumentException if an unsupported argument type is
* provided.
*/
public function withParsedBody($data);
public function withParsedBody($data): ServerRequestInterface;

/**
* Retrieve attributes derived from the request.
Expand All @@ -209,7 +207,7 @@ public function withParsedBody($data);
*
* @return array Attributes derived from the request.
*/
public function getAttributes();
public function getAttributes(): array;

/**
* Retrieve a single derived request attribute.
Expand Down Expand Up @@ -243,7 +241,7 @@ public function getAttribute(string $name, $default = null);
* @param mixed $value The value of the attribute.
* @return static
*/
public function withAttribute(string $name, $value);
public function withAttribute(string $name, $value): ServerRequestInterface;

/**
* Return an instance that removes the specified derived request attribute.
Expand All @@ -259,5 +257,5 @@ public function withAttribute(string $name, $value);
* @param string $name The attribute name.
* @return static
*/
public function withoutAttribute(string $name);
public function withoutAttribute(string $name): ServerRequestInterface;
}
Loading

0 comments on commit 402d35b

Please sign in to comment.