Skip to content

Commit fbd8878

Browse files
committed
up: fix some syntax error on php8.4
1 parent 22c4542 commit fbd8878

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

src/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Request implements RequestInterface
4545
public function __construct(
4646
string $method = 'GET',
4747
?UriInterface $uri = null,
48-
array|Headers $headers = null,
48+
array|Headers|null $headers = null,
4949
?StreamInterface $body = null,
5050
string $protocol = 'HTTP',
5151
string $protocolVersion = '1.1'

src/Stream.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ class Stream implements StreamInterface
6565
*
6666
* @var bool
6767
*/
68-
protected bool $readable;
68+
protected ?bool $readable;
6969

7070
/**
7171
* Is this stream writable?
7272
*
7373
* @var bool
7474
*/
75-
protected bool $writable;
75+
protected ?bool $writable;
7676

7777
/**
7878
* Is this stream seekable?
7979
*
8080
* @var bool
8181
*/
82-
protected bool $seekable;
82+
protected ?bool $seekable;
8383

8484
/**
8585
* The size of the stream if known
@@ -93,7 +93,7 @@ class Stream implements StreamInterface
9393
*
9494
* @var bool
9595
*/
96-
protected bool $isPipe;
96+
protected ?bool $isPipe;
9797

9898
/**
9999
* Create a new Stream.
@@ -115,13 +115,13 @@ public function __construct($stream)
115115
*
116116
* @link http://php.net/manual/en/function.stream-get-meta-data.php
117117
*
118-
* @param string $key Specific metadata to retrieve.
118+
* @param string|null $key Specific metadata to retrieve.
119119
*
120120
* @return array|mixed|null Returns an associative array if no key is
121121
* provided. Returns a specific key value if a key is provided and the
122122
* value is found, or null if the key is not found.
123123
*/
124-
public function getMetadata($key = null): mixed
124+
public function getMetadata(?string $key = null): mixed
125125
{
126126
$this->meta = \stream_get_meta_data($this->stream);
127127
if (null === $key) {
@@ -176,7 +176,7 @@ public function detach()
176176
{
177177
$oldResource = $this->stream;
178178
$this->stream = null;
179-
$this->meta = null;
179+
$this->meta = [];
180180
$this->readable = null;
181181
$this->writable = null;
182182
$this->seekable = null;
@@ -356,7 +356,7 @@ public function isSeekable(): bool
356356
*
357357
* @throws RuntimeException on failure.
358358
*/
359-
public function seek($offset, $whence = \SEEK_SET)
359+
public function seek(int $offset, $whence = \SEEK_SET)
360360
{
361361
// Note that fseek returns 0 on success!
362362
if (!$this->isSeekable() || fseek($this->stream, $offset, $whence) === -1) {
@@ -395,7 +395,7 @@ public function rewind()
395395
*
396396
* @throws RuntimeException if an error occurs.
397397
*/
398-
public function read($length): string
398+
public function read(int $length): string
399399
{
400400
if (!$this->isReadable() || ($data = fread($this->stream, $length)) === false) {
401401
throw new RuntimeException('Could not read from stream');
@@ -407,15 +407,15 @@ public function read($length): string
407407
/**
408408
* Write data to the stream.
409409
*
410-
* @param string $string The string that is to be written.
410+
* @param string $str The string that is to be written.
411411
*
412412
* @return int Returns the number of bytes written to the stream.
413413
*
414414
* @throws RuntimeException on failure.
415415
*/
416-
public function write($string): int
416+
public function write(string $str): int
417417
{
418-
if (!$this->isWritable() || ($written = fwrite($this->stream, $string)) === false) {
418+
if (!$this->isWritable() || ($written = fwrite($this->stream, $str)) === false) {
419419
throw new RuntimeException('Could not write to stream');
420420
}
421421

src/Traits/RequestTrait.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ trait RequestTrait
6868
*
6969
* @throws InvalidArgumentException
7070
*/
71-
protected function initializeRequest(UriInterface|string $uri = null, ?string $method = null): void
71+
protected function initializeRequest(UriInterface|string|null $uri = null, ?string $method = null): void
7272
{
7373
try {
7474
$this->originalMethod = $this->filterMethod($method);
@@ -87,11 +87,16 @@ protected function initializeRequest(UriInterface|string $uri = null, ?string $m
8787
*/
8888
protected function buildFirstLine(): string
8989
{
90+
$pathWithQuery = $this->uri->getPath();
91+
if ($queryStr = $this->uri->getQuery()) {
92+
$pathWithQuery .= '?' . $queryStr;
93+
}
94+
9095
// `GET /path HTTP/1.1`
9196
return sprintf(
9297
'%s %s %s/%s',
9398
$this->getMethod(),
94-
$this->uri->getPathAndQuery(),
99+
$pathWithQuery,
95100
$this->getProtocol(),
96101
$this->getProtocolVersion()
97102
);

0 commit comments

Comments
 (0)