Skip to content

Commit

Permalink
Add return typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
Stilch committed May 9, 2021
1 parent 5cd5ad7 commit 54df5d4
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
"dev-master": "2.0.x-dev"
}
}
}
22 changes: 11 additions & 11 deletions src/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 +40,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 +67,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 +77,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 +93,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 +114,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 +131,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 +149,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 +163,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 +185,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;
}
12 changes: 6 additions & 6 deletions src/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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 +60,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 +84,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 +95,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 +127,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;
}
6 changes: 3 additions & 3 deletions src/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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 +51,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 +66,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;
}
22 changes: 11 additions & 11 deletions src/ServerRequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface ServerRequestInterface extends RequestInterface
*
* @return array
*/
public function getServerParams();
public function getServerParams(): array;

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

/**
* Return an instance with the specified cookies.
Expand All @@ -84,7 +84,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 +98,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 +122,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 +136,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 +149,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 +196,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 +209,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 +243,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 +259,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;
}
18 changes: 9 additions & 9 deletions src/StreamInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,29 @@ public function detach();
*
* @return int|null Returns the size in bytes if known, or null if unknown.
*/
public function getSize();
public function getSize(): ?int;

/**
* Returns the current position of the file read/write pointer
*
* @return int Position of the file pointer
* @throws \RuntimeException on error.
*/
public function tell();
public function tell(): int;

/**
* Returns true if the stream is at the end of the stream.
*
* @return bool
*/
public function eof();
public function eof(): bool;

/**
* Returns whether or not the stream is seekable.
*
* @return bool
*/
public function isSeekable();
public function isSeekable(): bool;

/**
* Seek to a position in the stream.
Expand Down Expand Up @@ -105,7 +105,7 @@ public function rewind();
*
* @return bool
*/
public function isWritable();
public function isWritable(): bool;

/**
* Write data to the stream.
Expand All @@ -114,14 +114,14 @@ public function isWritable();
* @return int Returns the number of bytes written to the stream.
* @throws \RuntimeException on failure.
*/
public function write(string $string);
public function write(string $string): int;

/**
* Returns whether or not the stream is readable.
*
* @return bool
*/
public function isReadable();
public function isReadable(): bool;

/**
* Read data from the stream.
Expand All @@ -133,7 +133,7 @@ public function isReadable();
* if no bytes are available.
* @throws \RuntimeException if an error occurs.
*/
public function read(int $length);
public function read(int $length): string;

/**
* Returns the remaining contents in a string
Expand All @@ -142,7 +142,7 @@ public function read(int $length);
* @throws \RuntimeException if unable to read or an error occurs while
* reading.
*/
public function getContents();
public function getContents(): string;

/**
* Get stream metadata as an associative array or retrieve a specific key.
Expand Down
10 changes: 5 additions & 5 deletions src/UploadedFileInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface UploadedFileInterface
* @throws \RuntimeException in cases when no stream is available or can be
* created.
*/
public function getStream();
public function getStream(): StreamInterface;

/**
* Move the uploaded file to a new location.
Expand Down Expand Up @@ -75,7 +75,7 @@ public function moveTo(string $targetPath);
*
* @return int|null The file size in bytes or null if unknown.
*/
public function getSize();
public function getSize(): ?int;

/**
* Retrieve the error associated with the uploaded file.
Expand All @@ -91,7 +91,7 @@ public function getSize();
* @see http://php.net/manual/en/features.file-upload.errors.php
* @return int One of PHP's UPLOAD_ERR_XXX constants.
*/
public function getError();
public function getError(): int;

/**
* Retrieve the filename sent by the client.
Expand All @@ -106,7 +106,7 @@ public function getError();
* @return string|null The filename sent by the client or null if none
* was provided.
*/
public function getClientFilename();
public function getClientFilename(): ?string;

/**
* Retrieve the media type sent by the client.
Expand All @@ -121,5 +121,5 @@ public function getClientFilename();
* @return string|null The media type sent by the client or null if none
* was provided.
*/
public function getClientMediaType();
public function getClientMediaType(): ?string;
}
Loading

0 comments on commit 54df5d4

Please sign in to comment.