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

Commit acd3bee

Browse files
committed
Get status code return integer
1 parent 6b3c333 commit acd3bee

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/Response.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ public function withStatus($code, $reasonPhrase = '')
174174
*/
175175
private function setStatusCode($code)
176176
{
177-
if (! is_int($code)
177+
if (! is_numeric($code)
178+
|| is_float($code)
178179
|| $code < static::MIN_STATUS_CODE_VALUE
179180
|| $code > static::MAX_STATUS_CODE_VALUE
180181
) {
@@ -185,6 +186,6 @@ private function setStatusCode($code)
185186
static::MAX_STATUS_CODE_VALUE
186187
));
187188
}
188-
$this->statusCode = $code;
189+
$this->statusCode = (int) $code;
189190
}
190191
}

src/Response/Serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ private static function getStatusLine(StreamInterface $stream)
106106
throw new UnexpectedValueException('No status line detected');
107107
}
108108

109-
return [$matches['version'], (int) $matches['status'], isset($matches['reason']) ? $matches['reason'] : ''];
109+
return [$matches['version'], $matches['status'], isset($matches['reason']) ? $matches['reason'] : ''];
110110
}
111111
}

test/ResponseTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function ianaCodesReasonPhrasesProvider()
7878
$records = $xpath->query('//ns:record');
7979

8080
foreach ($records as $record) {
81-
$value = (int) $xpath->query('.//ns:value', $record)->item(0)->nodeValue;
81+
$value = $xpath->query('.//ns:value', $record)->item(0)->nodeValue;
8282
$description = $xpath->query('.//ns:description', $record)->item(0)->nodeValue;
8383

8484
if (in_array($description, ['Unassigned', '(Unused)'])) {
@@ -140,14 +140,18 @@ public function testCreateWithValidStatusCodes($code)
140140
{
141141
$response = $this->response->withStatus($code);
142142

143-
$this->assertSame($code, $response->getStatusCode());
143+
$result = $response->getStatusCode();
144+
145+
$this->assertSame((int) $code, $result);
146+
$this->assertInternalType('int', $result);
144147
}
145148

146149
public function validStatusCodes()
147150
{
148151
return [
149152
'minimum' => [100],
150153
'middle' => [300],
154+
'string-integer' => ['300'],
151155
'maximum' => [599],
152156
];
153157
}
@@ -185,7 +189,6 @@ public function invalidStatusCodes()
185189
'too-high' => [600],
186190
'null' => [null],
187191
'string' => ['foo'],
188-
'string-integer' => ['200'],
189192
];
190193
}
191194

0 commit comments

Comments
 (0)