Skip to content

Commit

Permalink
Accept null and bool header values again
Browse files Browse the repository at this point in the history
This is not according to PSR-7 which says `@param string|string[] $value Header value(s).` but for BC and missing type declarations it makes sense.
  • Loading branch information
Tobion committed Jul 1, 2019
1 parent dc78403 commit 91eebe8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/MessageTrait.php
Expand Up @@ -186,9 +186,9 @@ private function normalizeHeaderValue($value)
private function trimHeaderValues(array $values)
{
return array_map(function ($value) {
if (!is_string($value) && !is_numeric($value)) {
if (!is_scalar($value) && null !== $value) {
throw new \InvalidArgumentException(sprintf(
'Header value must be a string or numeric but %s provided.',
'Header value must be scalar or null but %s provided.',
is_object($value) ? get_class($value) : gettype($value)
));
}
Expand Down
3 changes: 1 addition & 2 deletions tests/ResponseTest.php
Expand Up @@ -263,8 +263,7 @@ public function invalidHeaderProvider()
return [
['foo', [], 'Header value can not be an empty array.'],
['', '', 'Header name can not be empty.'],
['foo', false, 'Header value must be a string or numeric but boolean provided'],
['foo', new \stdClass(), 'Header value must be a string or numeric but stdClass provided.'],
['foo', new \stdClass(), 'Header value must be scalar or null but stdClass provided.'],
];
}

Expand Down

0 comments on commit 91eebe8

Please sign in to comment.