diff --git a/src/Message/HeaderCollection.php b/src/Message/HeaderCollection.php index 97c3c99..6367e66 100644 --- a/src/Message/HeaderCollection.php +++ b/src/Message/HeaderCollection.php @@ -7,51 +7,44 @@ use Iterator; /** * HeaderCollection provides case-insensitive access to lists of header values. - * - * This class is an internal class used by Message and is not intended for - * direct use by consumers. - * + ** * HeaderCollection preserves the cases of keys as they are set, but treats key * access case insensitively. * * Any values added to HeaderCollection are added to list arrays. Subsequent * calls to add a value for a given key will append the new value to the list * array of values for that key. + * + * @internal This class is an internal class used by Message and is not intended + * for direct use by consumers. */ class HeaderCollection implements ArrayAccess, Iterator { /** - * @var array - * * Hash array mapping lowercase header names to original case header names. + * + * @var array */ - private $fields; + private $fields = []; /** - * @var array - * * Hash array mapping lowercase header names to values as string[] + * + * @var array */ - private $values; + private $values = []; /** - * @var string[] - * * List array of lowercase header names. + * + * @var string[] */ - private $keys; + private $keys = []; /** @var int */ private $position = 0; - public function __construct() - { - $this->keys = []; - $this->fields = []; - $this->values = []; - } - - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- // ArrayAccess /** @@ -111,7 +104,7 @@ class HeaderCollection implements ArrayAccess, Iterator } } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- // Iterator public function current() diff --git a/test/tests/unit/Message/HeaderCollectionTest.php b/test/tests/unit/Message/HeaderCollectionTest.php index 730b575..568dcbc 100644 --- a/test/tests/unit/Message/HeaderCollectionTest.php +++ b/test/tests/unit/Message/HeaderCollectionTest.php @@ -1,20 +1,19 @@ assertTrue(isset($collection['content-type'])); } - public function testAddsMultipleHeadersAndIndicatesCaseInsensitiveIsset() + public function testAddsMultipleHeadersAndIndicatesCaseInsensitiveIsset(): void { $collection = new HeaderCollection(); $collection['Set-Cookie'] = 'cat=Molly'; @@ -22,17 +21,18 @@ class HeaderCollectionTest extends TestCase $this->assertTrue(isset($collection['set-cookie'])); } - public function testReturnsHeadersWithCaseInsensitiveHeaderName() + public function testReturnsHeadersWithCaseInsensitiveHeaderName(): void { $collection = new HeaderCollection(); $collection['Set-Cookie'] = 'cat=Molly'; $collection['SET-COOKIE'] = 'dog=Bear'; $headers = $collection['set-cookie']; - $this->assertEquals(2, count(array_intersect($headers, ['cat=Molly', 'dog=Bear']))); + $matched = array_intersect($headers, ['cat=Molly', 'dog=Bear']); + $this->assertCount(2, $matched); } - public function testRemovesHeadersWithCaseInsensitiveHeaderName() + public function testRemovesHeadersWithCaseInsensitiveHeaderName(): void { $collection = new HeaderCollection(); $collection['Set-Cookie'] = 'cat=Molly'; @@ -41,8 +41,7 @@ class HeaderCollectionTest extends TestCase $this->assertFalse(isset($collection['set-cookie'])); } - /** @coversNothing */ - public function testCloneMakesDeepCopyOfHeaders() + public function testCloneMakesDeepCopyOfHeaders(): void { $collection = new HeaderCollection(); $collection['Set-Cookie'] = 'cat=Molly'; @@ -53,7 +52,7 @@ class HeaderCollectionTest extends TestCase $this->assertTrue(isset($collection['set-cookie']) && !isset($clone['set-cookie'])); } - public function testIteratesWithOriginalKeys() + public function testIteratesWithOriginalKeys(): void { $collection = new HeaderCollection(); $collection['Content-length'] = '100'; @@ -74,7 +73,7 @@ class HeaderCollectionTest extends TestCase $this->assertEquals(0, $countUnmatched); } - public function testIteratesWithOriginalKeysAndValues() + public function testIteratesWithOriginalKeysAndValues(): void { $collection = new HeaderCollection(); $collection['Content-length'] = '100';