Skip to content

Commit 54df5d4

Browse files
committed
Add return typehints
1 parent 5cd5ad7 commit 54df5d4

8 files changed

+61
-61
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"extra": {
2222
"branch-alias": {
23-
"dev-master": "1.1.x-dev"
23+
"dev-master": "2.0.x-dev"
2424
}
2525
}
2626
}

src/MessageInterface.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface MessageInterface
2525
*
2626
* @return string HTTP protocol version.
2727
*/
28-
public function getProtocolVersion();
28+
public function getProtocolVersion(): string;
2929

3030
/**
3131
* Return an instance with the specified HTTP protocol version.
@@ -40,7 +40,7 @@ public function getProtocolVersion();
4040
* @param string $version HTTP protocol version
4141
* @return static
4242
*/
43-
public function withProtocolVersion(string $version);
43+
public function withProtocolVersion(string $version): MessageInterface;
4444

4545
/**
4646
* Retrieves all message header values.
@@ -67,7 +67,7 @@ public function withProtocolVersion(string $version);
6767
* key MUST be a header name, and each value MUST be an array of strings
6868
* for that header.
6969
*/
70-
public function getHeaders();
70+
public function getHeaders(): array;
7171

7272
/**
7373
* Checks if a header exists by the given case-insensitive name.
@@ -77,7 +77,7 @@ public function getHeaders();
7777
* name using a case-insensitive string comparison. Returns false if
7878
* no matching header name is found in the message.
7979
*/
80-
public function hasHeader(string $name);
80+
public function hasHeader(string $name): bool;
8181

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

9898
/**
9999
* Retrieves a comma-separated string of the values for a single header.
@@ -114,7 +114,7 @@ public function getHeader(string $name);
114114
* concatenated together using a comma. If the header does not appear in
115115
* the message, this method MUST return an empty string.
116116
*/
117-
public function getHeaderLine(string $name);
117+
public function getHeaderLine(string $name): string;
118118

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

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

154154
/**
155155
* Return an instance without the specified header.
@@ -163,14 +163,14 @@ public function withAddedHeader(string $name, $value);
163163
* @param string $name Case-insensitive header field name to remove.
164164
* @return static
165165
*/
166-
public function withoutHeader(string $name);
166+
public function withoutHeader(string $name): MessageInterface;
167167

168168
/**
169169
* Gets the body of the message.
170170
*
171171
* @return StreamInterface Returns the body as a stream.
172172
*/
173-
public function getBody();
173+
public function getBody(): StreamInterface;
174174

175175
/**
176176
* Return an instance with the specified message body.
@@ -185,5 +185,5 @@ public function getBody();
185185
* @return static
186186
* @throws \InvalidArgumentException When the body is not valid.
187187
*/
188-
public function withBody(StreamInterface $body);
188+
public function withBody(StreamInterface $body): MessageInterface;
189189
}

src/RequestInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface RequestInterface extends MessageInterface
4141
*
4242
* @return string
4343
*/
44-
public function getRequestTarget();
44+
public function getRequestTarget(): string;
4545

4646
/**
4747
* Return an instance with the specific request-target.
@@ -60,14 +60,14 @@ public function getRequestTarget();
6060
* @param mixed $requestTarget
6161
* @return static
6262
*/
63-
public function withRequestTarget($requestTarget);
63+
public function withRequestTarget($requestTarget): RequestInterface;
6464

6565
/**
6666
* Retrieves the HTTP method of the request.
6767
*
6868
* @return string Returns the request method.
6969
*/
70-
public function getMethod();
70+
public function getMethod(): string;
7171

7272
/**
7373
* Return an instance with the provided HTTP method.
@@ -84,7 +84,7 @@ public function getMethod();
8484
* @return static
8585
* @throws \InvalidArgumentException for invalid HTTP methods.
8686
*/
87-
public function withMethod(string $method);
87+
public function withMethod(string $method): RequestInterface;
8888

8989
/**
9090
* Retrieves the URI instance.
@@ -95,7 +95,7 @@ public function withMethod(string $method);
9595
* @return UriInterface Returns a UriInterface instance
9696
* representing the URI of the request.
9797
*/
98-
public function getUri();
98+
public function getUri(): UriInterface;
9999

100100
/**
101101
* Returns an instance with the provided URI.
@@ -127,5 +127,5 @@ public function getUri();
127127
* @param bool $preserveHost Preserve the original state of the Host header.
128128
* @return static
129129
*/
130-
public function withUri(UriInterface $uri, bool $preserveHost = false);
130+
public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface;
131131
}

src/ResponseInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface ResponseInterface extends MessageInterface
2929
*
3030
* @return int Status code.
3131
*/
32-
public function getStatusCode();
32+
public function getStatusCode(): int;
3333

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

5656
/**
5757
* Gets the response reason phrase associated with the status code.
@@ -66,5 +66,5 @@ public function withStatus(int $code, string $reasonPhrase = '');
6666
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
6767
* @return string Reason phrase; must return an empty string if none present.
6868
*/
69-
public function getReasonPhrase();
69+
public function getReasonPhrase(): string;
7070
}

src/ServerRequestInterface.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ interface ServerRequestInterface extends RequestInterface
5353
*
5454
* @return array
5555
*/
56-
public function getServerParams();
56+
public function getServerParams(): array;
5757

5858
/**
5959
* Retrieve cookies.
@@ -65,7 +65,7 @@ public function getServerParams();
6565
*
6666
* @return array
6767
*/
68-
public function getCookieParams();
68+
public function getCookieParams(): array;
6969

7070
/**
7171
* Return an instance with the specified cookies.
@@ -84,7 +84,7 @@ public function getCookieParams();
8484
* @param array $cookies Array of key/value pairs representing cookies.
8585
* @return static
8686
*/
87-
public function withCookieParams(array $cookies);
87+
public function withCookieParams(array $cookies): ServerRequestInterface;
8888

8989
/**
9090
* Retrieve query string arguments.
@@ -98,7 +98,7 @@ public function withCookieParams(array $cookies);
9898
*
9999
* @return array
100100
*/
101-
public function getQueryParams();
101+
public function getQueryParams(): array;
102102

103103
/**
104104
* Return an instance with the specified query string arguments.
@@ -122,7 +122,7 @@ public function getQueryParams();
122122
* $_GET.
123123
* @return static
124124
*/
125-
public function withQueryParams(array $query);
125+
public function withQueryParams(array $query): ServerRequestInterface;
126126

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

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

154154
/**
155155
* Retrieve any parameters provided in the request body.
@@ -196,7 +196,7 @@ public function getParsedBody();
196196
* @throws \InvalidArgumentException if an unsupported argument type is
197197
* provided.
198198
*/
199-
public function withParsedBody($data);
199+
public function withParsedBody($data): ServerRequestInterface;
200200

201201
/**
202202
* Retrieve attributes derived from the request.
@@ -209,7 +209,7 @@ public function withParsedBody($data);
209209
*
210210
* @return array Attributes derived from the request.
211211
*/
212-
public function getAttributes();
212+
public function getAttributes(): array;
213213

214214
/**
215215
* Retrieve a single derived request attribute.
@@ -243,7 +243,7 @@ public function getAttribute(string $name, $default = null);
243243
* @param mixed $value The value of the attribute.
244244
* @return static
245245
*/
246-
public function withAttribute(string $name, $value);
246+
public function withAttribute(string $name, $value): ServerRequestInterface;
247247

248248
/**
249249
* Return an instance that removes the specified derived request attribute.
@@ -259,5 +259,5 @@ public function withAttribute(string $name, $value);
259259
* @param string $name The attribute name.
260260
* @return static
261261
*/
262-
public function withoutAttribute(string $name);
262+
public function withoutAttribute(string $name): ServerRequestInterface;
263263
}

src/StreamInterface.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,29 @@ public function detach();
5050
*
5151
* @return int|null Returns the size in bytes if known, or null if unknown.
5252
*/
53-
public function getSize();
53+
public function getSize(): ?int;
5454

5555
/**
5656
* Returns the current position of the file read/write pointer
5757
*
5858
* @return int Position of the file pointer
5959
* @throws \RuntimeException on error.
6060
*/
61-
public function tell();
61+
public function tell(): int;
6262

6363
/**
6464
* Returns true if the stream is at the end of the stream.
6565
*
6666
* @return bool
6767
*/
68-
public function eof();
68+
public function eof(): bool;
6969

7070
/**
7171
* Returns whether or not the stream is seekable.
7272
*
7373
* @return bool
7474
*/
75-
public function isSeekable();
75+
public function isSeekable(): bool;
7676

7777
/**
7878
* Seek to a position in the stream.
@@ -105,7 +105,7 @@ public function rewind();
105105
*
106106
* @return bool
107107
*/
108-
public function isWritable();
108+
public function isWritable(): bool;
109109

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

119119
/**
120120
* Returns whether or not the stream is readable.
121121
*
122122
* @return bool
123123
*/
124-
public function isReadable();
124+
public function isReadable(): bool;
125125

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

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

147147
/**
148148
* Get stream metadata as an associative array or retrieve a specific key.

src/UploadedFileInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface UploadedFileInterface
3030
* @throws \RuntimeException in cases when no stream is available or can be
3131
* created.
3232
*/
33-
public function getStream();
33+
public function getStream(): StreamInterface;
3434

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

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

9696
/**
9797
* Retrieve the filename sent by the client.
@@ -106,7 +106,7 @@ public function getError();
106106
* @return string|null The filename sent by the client or null if none
107107
* was provided.
108108
*/
109-
public function getClientFilename();
109+
public function getClientFilename(): ?string;
110110

111111
/**
112112
* Retrieve the media type sent by the client.
@@ -121,5 +121,5 @@ public function getClientFilename();
121121
* @return string|null The media type sent by the client or null if none
122122
* was provided.
123123
*/
124-
public function getClientMediaType();
124+
public function getClientMediaType(): ?string;
125125
}

0 commit comments

Comments
 (0)