Skip to content

Commit 402d35b

Browse files
authored
Merge pull request #95 from Stilch/add-param-and-return-type-hints
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/
2 parents cb6ce48 + 947607b commit 402d35b

8 files changed

+69
-82
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"authors": [
88
{
99
"name": "PHP-FIG",
10-
"homepage": "http://www.php-fig.org/"
10+
"homepage": "https://www.php-fig.org/"
1111
}
1212
],
1313
"require": {
@@ -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

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace Psr\Http\Message;
64

75
/**
@@ -25,7 +23,7 @@ interface MessageInterface
2523
*
2624
* @return string HTTP protocol version.
2725
*/
28-
public function getProtocolVersion();
26+
public function getProtocolVersion(): string;
2927

3028
/**
3129
* Return an instance with the specified HTTP protocol version.
@@ -40,7 +38,7 @@ public function getProtocolVersion();
4038
* @param string $version HTTP protocol version
4139
* @return static
4240
*/
43-
public function withProtocolVersion(string $version);
41+
public function withProtocolVersion(string $version): MessageInterface;
4442

4543
/**
4644
* Retrieves all message header values.
@@ -67,7 +65,7 @@ public function withProtocolVersion(string $version);
6765
* key MUST be a header name, and each value MUST be an array of strings
6866
* for that header.
6967
*/
70-
public function getHeaders();
68+
public function getHeaders(): array;
7169

7270
/**
7371
* Checks if a header exists by the given case-insensitive name.
@@ -77,7 +75,7 @@ public function getHeaders();
7775
* name using a case-insensitive string comparison. Returns false if
7876
* no matching header name is found in the message.
7977
*/
80-
public function hasHeader(string $name);
78+
public function hasHeader(string $name): bool;
8179

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

9896
/**
9997
* Retrieves a comma-separated string of the values for a single header.
@@ -114,7 +112,7 @@ public function getHeader(string $name);
114112
* concatenated together using a comma. If the header does not appear in
115113
* the message, this method MUST return an empty string.
116114
*/
117-
public function getHeaderLine(string $name);
115+
public function getHeaderLine(string $name): string;
118116

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

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

154152
/**
155153
* Return an instance without the specified header.
@@ -163,14 +161,14 @@ public function withAddedHeader(string $name, $value);
163161
* @param string $name Case-insensitive header field name to remove.
164162
* @return static
165163
*/
166-
public function withoutHeader(string $name);
164+
public function withoutHeader(string $name): MessageInterface;
167165

168166
/**
169167
* Gets the body of the message.
170168
*
171169
* @return StreamInterface Returns the body as a stream.
172170
*/
173-
public function getBody();
171+
public function getBody(): StreamInterface;
174172

175173
/**
176174
* Return an instance with the specified message body.
@@ -185,5 +183,5 @@ public function getBody();
185183
* @return static
186184
* @throws \InvalidArgumentException When the body is not valid.
187185
*/
188-
public function withBody(StreamInterface $body);
186+
public function withBody(StreamInterface $body): MessageInterface;
189187
}

src/RequestInterface.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace Psr\Http\Message;
64

75
/**
@@ -41,7 +39,7 @@ interface RequestInterface extends MessageInterface
4139
*
4240
* @return string
4341
*/
44-
public function getRequestTarget();
42+
public function getRequestTarget(): string;
4543

4644
/**
4745
* Return an instance with the specific request-target.
@@ -60,14 +58,15 @@ public function getRequestTarget();
6058
* @param string $requestTarget
6159
* @return static
6260
*/
63-
public function withRequestTarget(string $requestTarget);
61+
public function withRequestTarget(string $requestTarget): RequestInterface;
62+
6463

6564
/**
6665
* Retrieves the HTTP method of the request.
6766
*
6867
* @return string Returns the request method.
6968
*/
70-
public function getMethod();
69+
public function getMethod(): string;
7170

7271
/**
7372
* Return an instance with the provided HTTP method.
@@ -84,7 +83,7 @@ public function getMethod();
8483
* @return static
8584
* @throws \InvalidArgumentException for invalid HTTP methods.
8685
*/
87-
public function withMethod(string $method);
86+
public function withMethod(string $method): RequestInterface;
8887

8988
/**
9089
* Retrieves the URI instance.
@@ -95,7 +94,7 @@ public function withMethod(string $method);
9594
* @return UriInterface Returns a UriInterface instance
9695
* representing the URI of the request.
9796
*/
98-
public function getUri();
97+
public function getUri(): UriInterface;
9998

10099
/**
101100
* Returns an instance with the provided URI.
@@ -127,5 +126,5 @@ public function getUri();
127126
* @param bool $preserveHost Preserve the original state of the Host header.
128127
* @return static
129128
*/
130-
public function withUri(UriInterface $uri, bool $preserveHost = false);
129+
public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface;
131130
}

src/ResponseInterface.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace Psr\Http\Message;
64

75
/**
@@ -29,7 +27,7 @@ interface ResponseInterface extends MessageInterface
2927
*
3028
* @return int Status code.
3129
*/
32-
public function getStatusCode();
30+
public function getStatusCode(): int;
3331

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

5654
/**
5755
* Gets the response reason phrase associated with the status code.
@@ -66,5 +64,5 @@ public function withStatus(int $code, string $reasonPhrase = '');
6664
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
6765
* @return string Reason phrase; must return an empty string if none present.
6866
*/
69-
public function getReasonPhrase();
67+
public function getReasonPhrase(): string;
7068
}

src/ServerRequestInterface.php

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace Psr\Http\Message;
64

75
/**
@@ -53,7 +51,7 @@ interface ServerRequestInterface extends RequestInterface
5351
*
5452
* @return array
5553
*/
56-
public function getServerParams();
54+
public function getServerParams(): array;
5755

5856
/**
5957
* Retrieve cookies.
@@ -65,7 +63,7 @@ public function getServerParams();
6563
*
6664
* @return array
6765
*/
68-
public function getCookieParams();
66+
public function getCookieParams(): array;
6967

7068
/**
7169
* Return an instance with the specified cookies.
@@ -84,7 +82,7 @@ public function getCookieParams();
8482
* @param array $cookies Array of key/value pairs representing cookies.
8583
* @return static
8684
*/
87-
public function withCookieParams(array $cookies);
85+
public function withCookieParams(array $cookies): ServerRequestInterface;
8886

8987
/**
9088
* Retrieve query string arguments.
@@ -98,7 +96,7 @@ public function withCookieParams(array $cookies);
9896
*
9997
* @return array
10098
*/
101-
public function getQueryParams();
99+
public function getQueryParams(): array;
102100

103101
/**
104102
* Return an instance with the specified query string arguments.
@@ -122,7 +120,7 @@ public function getQueryParams();
122120
* $_GET.
123121
* @return static
124122
*/
125-
public function withQueryParams(array $query);
123+
public function withQueryParams(array $query): ServerRequestInterface;
126124

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

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

154152
/**
155153
* Retrieve any parameters provided in the request body.
@@ -196,7 +194,7 @@ public function getParsedBody();
196194
* @throws \InvalidArgumentException if an unsupported argument type is
197195
* provided.
198196
*/
199-
public function withParsedBody($data);
197+
public function withParsedBody($data): ServerRequestInterface;
200198

201199
/**
202200
* Retrieve attributes derived from the request.
@@ -209,7 +207,7 @@ public function withParsedBody($data);
209207
*
210208
* @return array Attributes derived from the request.
211209
*/
212-
public function getAttributes();
210+
public function getAttributes(): array;
213211

214212
/**
215213
* Retrieve a single derived request attribute.
@@ -243,7 +241,7 @@ public function getAttribute(string $name, $default = null);
243241
* @param mixed $value The value of the attribute.
244242
* @return static
245243
*/
246-
public function withAttribute(string $name, $value);
244+
public function withAttribute(string $name, $value): ServerRequestInterface;
247245

248246
/**
249247
* Return an instance that removes the specified derived request attribute.
@@ -259,5 +257,5 @@ public function withAttribute(string $name, $value);
259257
* @param string $name The attribute name.
260258
* @return static
261259
*/
262-
public function withoutAttribute(string $name);
260+
public function withoutAttribute(string $name): ServerRequestInterface;
263261
}

0 commit comments

Comments
 (0)