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

PHP8 "static" return type #107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": "^7.2 || ^8.0"
"php": "^8.0"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 5 additions & 5 deletions src/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getProtocolVersion(): string;
* @param string $version HTTP protocol version
* @return static
*/
public function withProtocolVersion(string $version): MessageInterface;
public function withProtocolVersion(string $version): static;

/**
* Retrieves all message header values.
Expand Down Expand Up @@ -129,7 +129,7 @@ public function getHeaderLine(string $name): string;
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withHeader(string $name, $value): MessageInterface;
public function withHeader(string $name, array|string $value): static;
Copy link
Author

Choose a reason for hiding this comment

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

Thinking about it, this should rather accept mixed to include scalar types, as some implementations are already implemented this way, ignoring the defined type in the docblock.


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

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

/**
* Gets the body of the message.
Expand All @@ -183,5 +183,5 @@ public function getBody(): StreamInterface;
* @return static
* @throws \InvalidArgumentException When the body is not valid.
*/
public function withBody(StreamInterface $body): MessageInterface;
public function withBody(StreamInterface $body): static;
}
6 changes: 3 additions & 3 deletions src/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getRequestTarget(): string;
* @param string $requestTarget
* @return static
*/
public function withRequestTarget(string $requestTarget): RequestInterface;
public function withRequestTarget(string $requestTarget): static;


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

/**
* Retrieves the URI instance.
Expand Down Expand Up @@ -126,5 +126,5 @@ public function getUri(): UriInterface;
* @param bool $preserveHost Preserve the original state of the Host header.
* @return static
*/
public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface;
public function withUri(UriInterface $uri, bool $preserveHost = false): static;
}
2 changes: 1 addition & 1 deletion src/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getStatusCode(): int;
* @return static
* @throws \InvalidArgumentException For invalid status code arguments.
*/
public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface;
public function withStatus(int $code, string $reasonPhrase = ''): static;

/**
* Gets the response reason phrase associated with the status code.
Expand Down
16 changes: 8 additions & 8 deletions src/ServerRequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getCookieParams(): array;
* @param array $cookies Array of key/value pairs representing cookies.
* @return static
*/
public function withCookieParams(array $cookies): ServerRequestInterface;
public function withCookieParams(array $cookies): static;

/**
* Retrieve query string arguments.
Expand Down Expand Up @@ -120,7 +120,7 @@ public function getQueryParams(): array;
* $_GET.
* @return static
*/
public function withQueryParams(array $query): ServerRequestInterface;
public function withQueryParams(array $query): static;

/**
* Retrieve normalized file upload data.
Expand All @@ -147,7 +147,7 @@ public function getUploadedFiles(): array;
* @return static
* @throws \InvalidArgumentException if an invalid structure is provided.
*/
public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface;
public function withUploadedFiles(array $uploadedFiles): static;

/**
* Retrieve any parameters provided in the request body.
Expand All @@ -164,7 +164,7 @@ public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface;
* @return null|array|object The deserialized body parameters, if any.
* These will typically be an array or object.
*/
public function getParsedBody();
public function getParsedBody(): null|array|object;

/**
* Return an instance with the specified body parameters.
Expand Down Expand Up @@ -194,7 +194,7 @@ public function getParsedBody();
* @throws \InvalidArgumentException if an unsupported argument type is
* provided.
*/
public function withParsedBody($data): ServerRequestInterface;
public function withParsedBody(null|array|object $data): static;

/**
* Retrieve attributes derived from the request.
Expand Down Expand Up @@ -224,7 +224,7 @@ public function getAttributes(): array;
* @param mixed $default Default value to return if the attribute does not exist.
* @return mixed
*/
public function getAttribute(string $name, $default = null);
public function getAttribute(string $name, mixed $default = null): mixed;

/**
* Return an instance with the specified derived request attribute.
Expand All @@ -241,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): ServerRequestInterface;
public function withAttribute(string $name, mixed $value): static;

/**
* Return an instance that removes the specified derived request attribute.
Expand All @@ -257,5 +257,5 @@ public function withAttribute(string $name, $value): ServerRequestInterface;
* @param string $name The attribute name.
* @return static
*/
public function withoutAttribute(string $name): ServerRequestInterface;
public function withoutAttribute(string $name): static;
}
4 changes: 2 additions & 2 deletions src/StreamInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function close(): void;
*
* @return resource|null Underlying PHP stream, if any
*/
public function detach();
public function detach(): mixed;

/**
* Get the size of the stream if known.
Expand Down Expand Up @@ -154,5 +154,5 @@ public function getContents(): string;
* provided. Returns a specific key value if a key is provided and the
* value is found, or null if the key is not found.
*/
public function getMetadata(?string $key = null);
public function getMetadata(?string $key = null): mixed;
}
14 changes: 7 additions & 7 deletions src/UriInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function getFragment(): string;
* @return static A new instance with the specified scheme.
* @throws \InvalidArgumentException for invalid or unsupported schemes.
*/
public function withScheme(string $scheme): UriInterface;
public function withScheme(string $scheme): static;

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

/**
* Return an instance with the specified host.
Expand All @@ -219,7 +219,7 @@ public function withUserInfo(string $user, ?string $password = null): UriInterfa
* @return static A new instance with the specified host.
* @throws \InvalidArgumentException for invalid hostnames.
*/
public function withHost(string $host): UriInterface;
public function withHost(string $host): static;

/**
* Return an instance with the specified port.
Expand All @@ -238,7 +238,7 @@ public function withHost(string $host): UriInterface;
* @return static A new instance with the specified port.
* @throws \InvalidArgumentException for invalid ports.
*/
public function withPort(?int $port): UriInterface;
public function withPort(?int $port): static;

/**
* Return an instance with the specified path.
Expand All @@ -262,7 +262,7 @@ public function withPort(?int $port): UriInterface;
* @return static A new instance with the specified path.
* @throws \InvalidArgumentException for invalid paths.
*/
public function withPath(string $path): UriInterface;
public function withPath(string $path): static;

/**
* Return an instance with the specified query string.
Expand All @@ -279,7 +279,7 @@ public function withPath(string $path): UriInterface;
* @return static A new instance with the specified query string.
* @throws \InvalidArgumentException for invalid query strings.
*/
public function withQuery(string $query): UriInterface;
public function withQuery(string $query): static;

/**
* Return an instance with the specified URI fragment.
Expand All @@ -295,7 +295,7 @@ public function withQuery(string $query): UriInterface;
* @param string $fragment The fragment to use with the new instance.
* @return static A new instance with the specified fragment.
*/
public function withFragment(string $fragment): UriInterface;
public function withFragment(string $fragment): static;

/**
* Return the string representation as a URI reference.
Expand Down