Skip to content

Commit 247d687

Browse files
committed
Upgrade the minimum php version to 8.0 for http-message.
1 parent 929ecfb commit 247d687

21 files changed

+245
-599
lines changed

src/Base/MessageTrait.php

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,13 @@ trait MessageTrait
2323
/**
2424
* @var array lowercase headers
2525
*/
26-
protected $headerNames;
26+
protected array $headerNames = [];
2727

28-
/**
29-
* @var array
30-
*/
31-
protected $headers = [];
28+
protected array $headers = [];
3229

33-
/**
34-
* @var string
35-
*/
36-
protected $protocol = '1.1';
30+
protected string $protocol = '1.1';
3731

38-
/**
39-
* @var null|StreamInterface
40-
*/
41-
protected $stream;
32+
protected ?StreamInterface $stream = null;
4233

4334
/**
4435
* Retrieves the HTTP protocol version as a string.
@@ -190,10 +181,7 @@ public function withHeader($name, $value)
190181
return $new;
191182
}
192183

193-
/**
194-
* @return static
195-
*/
196-
public function withHeaders(array $headers)
184+
public function withHeaders(array $headers): static
197185
{
198186
$new = clone $this;
199187
foreach ($headers as $name => $value) {
@@ -314,7 +302,7 @@ public function withBody(StreamInterface $body)
314302
* @throws \RuntimeException
315303
* @return array|string wanted part or all parts as array($firstName => firstPart, partname => value)
316304
*/
317-
public function getHeaderField($name, $wantedPart = '0', $firstName = '0')
305+
public function getHeaderField(string $name, string $wantedPart = '0', string $firstName = '0')
318306
{
319307
return Decode::splitHeaderField($this->getHeaderLine($name), $wantedPart, $firstName);
320308
}
@@ -338,10 +326,7 @@ public function isMultipart(): bool
338326
}
339327
}
340328

341-
/**
342-
* @return static
343-
*/
344-
private function setHeaders(array $headers)
329+
private function setHeaders(array $headers): static
345330
{
346331
$this->headerNames = $this->headers = [];
347332
foreach ($headers as $header => $value) {
@@ -374,7 +359,7 @@ private function setHeaders(array $headers)
374359
* @return string[] Trimmed header values
375360
* @see https://tools.ietf.org/html/rfc7230#section-3.2.4
376361
*/
377-
private function trimHeaderValues(array $values)
362+
private function trimHeaderValues(array $values): array
378363
{
379364
return array_map(function ($value) {
380365
return trim((string) $value, " \t");

src/Base/Request.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,13 @@ class Request implements RequestInterface
2121
{
2222
use MessageTrait;
2323

24-
/**
25-
* @var array
26-
*/
27-
protected $server = [];
24+
protected array $server = [];
2825

29-
/**
30-
* @var UriInterface
31-
*/
32-
protected $uri;
26+
protected UriInterface $uri;
3327

34-
/**
35-
* Http Method.
36-
*
37-
* @var string
38-
*/
39-
protected $method;
28+
protected string $method;
4029

41-
/**
42-
* @var string
43-
*/
44-
protected $requestTarget;
30+
protected ?string $requestTarget = null;
4531

4632
/**
4733
* @param string $method HTTP method
@@ -52,9 +38,9 @@ class Request implements RequestInterface
5238
*/
5339
public function __construct(
5440
string $method,
55-
$uri,
41+
string|UriInterface $uri,
5642
array $headers = [],
57-
$body = null,
43+
mixed $body = null,
5844
string $version = '1.1'
5945
) {
6046
if (! $uri instanceof UriInterface) {
@@ -185,7 +171,7 @@ public function getUri(): UriInterface
185171
* default if the URI contains a host component. If the URI does not
186172
* contain a host component, any pre-existing Host header MUST be carried
187173
* over to the returned request.
188-
* You can opt-in to preserving the original state of the Host header by
174+
* You can opt in to preserving the original state of the Host header by
189175
* setting `$preserveHost` to `true`. When `$preserveHost` is set to
190176
* `true`, this method interacts with the Host header in the following ways:
191177
* - If the Host header is missing or empty, and the new URI contains
@@ -226,7 +212,7 @@ public function withUri(UriInterface $uri, $preserveHost = false): self
226212
*
227213
* @see http://tools.ietf.org/html/rfc7230#section-5.4
228214
*/
229-
private function updateHostFromUri()
215+
private function updateHostFromUri(): void
230216
{
231217
$host = $this->uri->getHost();
232218

src/Base/Response.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,17 @@ class Response implements ResponseInterface
1717
{
1818
use MessageTrait;
1919

20-
/**
21-
* @var string
22-
*/
23-
protected $reasonPhrase = '';
20+
protected string $reasonPhrase = '';
2421

25-
/**
26-
* @var int
27-
*/
28-
protected $statusCode = 200;
22+
protected int $statusCode = 200;
23+
24+
protected string $charset = 'utf-8';
2925

3026
/**
31-
* @var string
27+
* Map of standard HTTP status code/reason phrases.
28+
* @var array<int, string>
3229
*/
33-
protected $charset = 'utf-8';
34-
35-
/** @var array Map of standard HTTP status code/reason phrases */
36-
private static $phrases
30+
private static array $phrases
3731
= [
3832
100 => 'Continue',
3933
101 => 'Switching Protocols',
@@ -95,10 +89,7 @@ class Response implements ResponseInterface
9589
511 => 'Network Authentication Required',
9690
];
9791

98-
/**
99-
* @var array
100-
*/
101-
private $attributes = [];
92+
private array $attributes = [];
10293

10394
public function __toString()
10495
{
@@ -115,7 +106,7 @@ public function __toString()
115106
*
116107
* @return array attributes derived from the request
117108
*/
118-
public function getAttributes()
109+
public function getAttributes(): array
119110
{
120111
return $this->attributes;
121112
}
@@ -332,7 +323,7 @@ public function isRedirect(string $location = null): bool
332323
303,
333324
307,
334325
308,
335-
]) && ($location === null ?: $location == $this->getHeaderLine('Location'));
326+
]) && ($location === null || $location == $this->getHeaderLine('Location'));
336327
}
337328

338329
/**

0 commit comments

Comments
 (0)