Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return typehints #95

Merged
merged 5 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
"homepage": "https://www.php-fig.org/"
}
],
"require": {
"php": ">=7.2.0"
"php": "^7.2.0 || ^8.0.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with the first PR, let's go straight to 8. There are no supported 7.x versions anymore.

Copy link
Contributor

@weierophinney weierophinney Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree.

Ubuntu 20.04, RHEL 7, and Debian 11 are all pinned to PHP 7.4 still, and these are all LTS editions. It makes sense to allow them to be able to update to the 1.1 release.

},
"autoload": {
"psr-4": {
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;
}
14 changes: 6 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,14 @@ public function getRequestTarget();
* @param mixed $requestTarget
* @return static
*/
public function withRequestTarget($requestTarget);
public function withRequestTarget($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 +82,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 +93,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 +125,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