Skip to content

Commit cb6ce48

Browse files
authored
Merge pull request #94 from Stilch/add-param-hints
Adds parameter typehints, as per the erata Since [psr/http-message version 1.1](https://packagist.org/packages/psr/http-message#1.1.0), the above interfaces have been updated to add argument type declarations. https://www.php-fig.org/psr/psr-7/meta/
2 parents efd67d1 + 6ae06cd commit cb6ce48

8 files changed

+45
-30
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=5.3.0"
14+
"php": "^7.2 || ^8.0"
1515
},
1616
"autoload": {
1717
"psr-4": {
@@ -20,7 +20,7 @@
2020
},
2121
"extra": {
2222
"branch-alias": {
23-
"dev-master": "1.0.x-dev"
23+
"dev-master": "1.1.x-dev"
2424
}
2525
}
2626
}

src/MessageInterface.php

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

3+
declare(strict_types=1);
4+
35
namespace Psr\Http\Message;
46

57
/**
@@ -38,7 +40,7 @@ public function getProtocolVersion();
3840
* @param string $version HTTP protocol version
3941
* @return static
4042
*/
41-
public function withProtocolVersion($version);
43+
public function withProtocolVersion(string $version);
4244

4345
/**
4446
* Retrieves all message header values.
@@ -75,7 +77,7 @@ public function getHeaders();
7577
* name using a case-insensitive string comparison. Returns false if
7678
* no matching header name is found in the message.
7779
*/
78-
public function hasHeader($name);
80+
public function hasHeader(string $name);
7981

8082
/**
8183
* Retrieves a message header value by the given case-insensitive name.
@@ -91,7 +93,7 @@ public function hasHeader($name);
9193
* header. If the header does not appear in the message, this method MUST
9294
* return an empty array.
9395
*/
94-
public function getHeader($name);
96+
public function getHeader(string $name);
9597

9698
/**
9799
* Retrieves a comma-separated string of the values for a single header.
@@ -112,7 +114,7 @@ public function getHeader($name);
112114
* concatenated together using a comma. If the header does not appear in
113115
* the message, this method MUST return an empty string.
114116
*/
115-
public function getHeaderLine($name);
117+
public function getHeaderLine(string $name);
116118

117119
/**
118120
* Return an instance with the provided value replacing the specified header.
@@ -129,7 +131,7 @@ public function getHeaderLine($name);
129131
* @return static
130132
* @throws \InvalidArgumentException for invalid header names or values.
131133
*/
132-
public function withHeader($name, $value);
134+
public function withHeader(string $name, $value);
133135

134136
/**
135137
* Return an instance with the specified header appended with the given value.
@@ -147,7 +149,7 @@ public function withHeader($name, $value);
147149
* @return static
148150
* @throws \InvalidArgumentException for invalid header names or values.
149151
*/
150-
public function withAddedHeader($name, $value);
152+
public function withAddedHeader(string $name, $value);
151153

152154
/**
153155
* Return an instance without the specified header.
@@ -161,7 +163,7 @@ public function withAddedHeader($name, $value);
161163
* @param string $name Case-insensitive header field name to remove.
162164
* @return static
163165
*/
164-
public function withoutHeader($name);
166+
public function withoutHeader(string $name);
165167

166168
/**
167169
* Gets the body of the message.

src/RequestInterface.php

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

3+
declare(strict_types=1);
4+
35
namespace Psr\Http\Message;
46

57
/**
@@ -55,10 +57,10 @@ public function getRequestTarget();
5557
*
5658
* @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various
5759
* request-target forms allowed in request messages)
58-
* @param mixed $requestTarget
60+
* @param string $requestTarget
5961
* @return static
6062
*/
61-
public function withRequestTarget($requestTarget);
63+
public function withRequestTarget(string $requestTarget);
6264

6365
/**
6466
* Retrieves the HTTP method of the request.
@@ -82,7 +84,7 @@ public function getMethod();
8284
* @return static
8385
* @throws \InvalidArgumentException for invalid HTTP methods.
8486
*/
85-
public function withMethod($method);
87+
public function withMethod(string $method);
8688

8789
/**
8890
* Retrieves the URI instance.
@@ -125,5 +127,5 @@ public function getUri();
125127
* @param bool $preserveHost Preserve the original state of the Host header.
126128
* @return static
127129
*/
128-
public function withUri(UriInterface $uri, $preserveHost = false);
130+
public function withUri(UriInterface $uri, bool $preserveHost = false);
129131
}

src/ResponseInterface.php

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

3+
declare(strict_types=1);
4+
35
namespace Psr\Http\Message;
46

57
/**
@@ -49,7 +51,7 @@ public function getStatusCode();
4951
* @return static
5052
* @throws \InvalidArgumentException For invalid status code arguments.
5153
*/
52-
public function withStatus($code, $reasonPhrase = '');
54+
public function withStatus(int $code, string $reasonPhrase = '');
5355

5456
/**
5557
* Gets the response reason phrase associated with the status code.

src/ServerRequestInterface.php

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

3+
declare(strict_types=1);
4+
35
namespace Psr\Http\Message;
46

57
/**
@@ -224,7 +226,7 @@ public function getAttributes();
224226
* @param mixed $default Default value to return if the attribute does not exist.
225227
* @return mixed
226228
*/
227-
public function getAttribute($name, $default = null);
229+
public function getAttribute(string $name, $default = null);
228230

229231
/**
230232
* Return an instance with the specified derived request attribute.
@@ -241,7 +243,7 @@ public function getAttribute($name, $default = null);
241243
* @param mixed $value The value of the attribute.
242244
* @return static
243245
*/
244-
public function withAttribute($name, $value);
246+
public function withAttribute(string $name, $value);
245247

246248
/**
247249
* Return an instance that removes the specified derived request attribute.
@@ -257,5 +259,5 @@ public function withAttribute($name, $value);
257259
* @param string $name The attribute name.
258260
* @return static
259261
*/
260-
public function withoutAttribute($name);
262+
public function withoutAttribute(string $name);
261263
}

src/StreamInterface.php

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

3+
declare(strict_types=1);
4+
35
namespace Psr\Http\Message;
46

57
/**
@@ -84,7 +86,7 @@ public function isSeekable();
8486
* SEEK_END: Set position to end-of-stream plus offset.
8587
* @throws \RuntimeException on failure.
8688
*/
87-
public function seek($offset, $whence = SEEK_SET);
89+
public function seek(int $offset, int $whence = SEEK_SET);
8890

8991
/**
9092
* Seek to the beginning of the stream.
@@ -112,7 +114,7 @@ public function isWritable();
112114
* @return int Returns the number of bytes written to the stream.
113115
* @throws \RuntimeException on failure.
114116
*/
115-
public function write($string);
117+
public function write(string $string);
116118

117119
/**
118120
* Returns whether or not the stream is readable.
@@ -131,7 +133,7 @@ public function isReadable();
131133
* if no bytes are available.
132134
* @throws \RuntimeException if an error occurs.
133135
*/
134-
public function read($length);
136+
public function read(int $length);
135137

136138
/**
137139
* Returns the remaining contents in a string
@@ -149,10 +151,10 @@ public function getContents();
149151
* stream_get_meta_data() function.
150152
*
151153
* @link http://php.net/manual/en/function.stream-get-meta-data.php
152-
* @param string $key Specific metadata to retrieve.
154+
* @param string|null $key Specific metadata to retrieve.
153155
* @return array|mixed|null Returns an associative array if no key is
154156
* provided. Returns a specific key value if a key is provided and the
155157
* value is found, or null if the key is not found.
156158
*/
157-
public function getMetadata($key = null);
159+
public function getMetadata(?string $key = null);
158160
}

src/UploadedFileInterface.php

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

3+
declare(strict_types=1);
4+
35
namespace Psr\Http\Message;
46

57
/**
@@ -62,7 +64,7 @@ public function getStream();
6264
* @throws \RuntimeException on any error during the move operation, or on
6365
* the second or subsequent call to the method.
6466
*/
65-
public function moveTo($targetPath);
67+
public function moveTo(string $targetPath);
6668

6769
/**
6870
* Retrieve the file size.

src/UriInterface.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Psr\Http\Message;
36

47
/**
@@ -188,7 +191,7 @@ public function getFragment();
188191
* @return static A new instance with the specified scheme.
189192
* @throws \InvalidArgumentException for invalid or unsupported schemes.
190193
*/
191-
public function withScheme($scheme);
194+
public function withScheme(string $scheme);
192195

193196
/**
194197
* Return an instance with the specified user information.
@@ -204,7 +207,7 @@ public function withScheme($scheme);
204207
* @param null|string $password The password associated with $user.
205208
* @return static A new instance with the specified user information.
206209
*/
207-
public function withUserInfo($user, $password = null);
210+
public function withUserInfo(string $user, ?string $password = null);
208211

209212
/**
210213
* Return an instance with the specified host.
@@ -218,7 +221,7 @@ public function withUserInfo($user, $password = null);
218221
* @return static A new instance with the specified host.
219222
* @throws \InvalidArgumentException for invalid hostnames.
220223
*/
221-
public function withHost($host);
224+
public function withHost(string $host);
222225

223226
/**
224227
* Return an instance with the specified port.
@@ -237,7 +240,7 @@ public function withHost($host);
237240
* @return static A new instance with the specified port.
238241
* @throws \InvalidArgumentException for invalid ports.
239242
*/
240-
public function withPort($port);
243+
public function withPort(?int $port);
241244

242245
/**
243246
* Return an instance with the specified path.
@@ -261,7 +264,7 @@ public function withPort($port);
261264
* @return static A new instance with the specified path.
262265
* @throws \InvalidArgumentException for invalid paths.
263266
*/
264-
public function withPath($path);
267+
public function withPath(string $path);
265268

266269
/**
267270
* Return an instance with the specified query string.
@@ -278,7 +281,7 @@ public function withPath($path);
278281
* @return static A new instance with the specified query string.
279282
* @throws \InvalidArgumentException for invalid query strings.
280283
*/
281-
public function withQuery($query);
284+
public function withQuery(string $query);
282285

283286
/**
284287
* Return an instance with the specified URI fragment.
@@ -294,7 +297,7 @@ public function withQuery($query);
294297
* @param string $fragment The fragment to use with the new instance.
295298
* @return static A new instance with the specified fragment.
296299
*/
297-
public function withFragment($fragment);
300+
public function withFragment(string $fragment);
298301

299302
/**
300303
* Return the string representation as a URI reference.

0 commit comments

Comments
 (0)