Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit d2cd6b5

Browse files
committed
Use nullable return type for parseContentRange
1 parent c20de15 commit d2cd6b5

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/Emitter/SapiStreamEmitter.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public function emit(ResponseInterface $response) : bool
3939

4040
$range = $this->parseContentRange($response->getHeaderLine('Content-Range'));
4141

42-
if (is_array($range) && $range[0] === 'bytes') {
43-
$this->emitBodyRange($range, $response);
42+
if (null === $range || 'bytes' !== $range[0]) {
43+
$this->emitBody($response);
4444
return true;
4545
}
4646

47-
$this->emitBody($response);
47+
$this->emitBodyRange($range, $response);
4848
return true;
4949
}
5050

@@ -93,7 +93,7 @@ private function emitBodyRange(array $range, ResponseInterface $response) : void
9393

9494
$remaining = $length;
9595

96-
while ($remaining >= $maxBufferLength && ! $body->eof()) {
96+
while ($remaining >= $this->maxBufferLength && ! $body->eof()) {
9797
$contents = $body->read($this->maxBufferLength);
9898
$remaining -= strlen($contents);
9999

@@ -109,19 +109,20 @@ private function emitBodyRange(array $range, ResponseInterface $response) : void
109109
* Parse content-range header
110110
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
111111
*
112-
* @return false|array [unit, first, last, length]; returns false if no
112+
* @return null|array [unit, first, last, length]; returns null if no
113113
* content range or an invalid content range is provided
114114
*/
115-
private function parseContentRange(string $header)
115+
private function parseContentRange(string $header) : ?array
116116
{
117-
if (preg_match('/(?P<unit>[\w]+)\s+(?P<first>\d+)-(?P<last>\d+)\/(?P<length>\d+|\*)/', $header, $matches)) {
118-
return [
119-
$matches['unit'],
120-
(int) $matches['first'],
121-
(int) $matches['last'],
122-
$matches['length'] === '*' ? '*' : (int) $matches['length'],
123-
];
117+
if (! preg_match('/(?P<unit>[\w]+)\s+(?P<first>\d+)-(?P<last>\d+)\/(?P<length>\d+|\*)/', $header, $matches)) {
118+
return null;
124119
}
125-
return false;
120+
121+
return [
122+
$matches['unit'],
123+
(int) $matches['first'],
124+
(int) $matches['last'],
125+
$matches['length'] === '*' ? '*' : (int) $matches['length'],
126+
];
126127
}
127128
}

0 commit comments

Comments
 (0)