From 91eebe82a902e87fec0742a77d914202e6f66320 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Mon, 1 Jul 2019 18:00:09 +0200 Subject: [PATCH 1/2] Accept null and bool header values again 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. --- src/MessageTrait.php | 4 ++-- tests/ResponseTest.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/MessageTrait.php b/src/MessageTrait.php index b7cf98b5..a7966d10 100644 --- a/src/MessageTrait.php +++ b/src/MessageTrait.php @@ -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) )); } diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index b0093bb8..2f184347 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -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.'], ]; } From 95622d397de273510ec3401530ddbac17a50cb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20S=C3=A1gi-Kaz=C3=A1r?= Date: Tue, 2 Jul 2019 01:16:10 +0200 Subject: [PATCH 2/2] Remove double whitespace --- tests/ResponseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 2f184347..61485057 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -263,7 +263,7 @@ public function invalidHeaderProvider() return [ ['foo', [], 'Header value can not be an empty array.'], ['', '', 'Header name can not be empty.'], - ['foo', new \stdClass(), 'Header value must be scalar or null but stdClass provided.'], + ['foo', new \stdClass(), 'Header value must be scalar or null but stdClass provided.'], ]; }