diff --git a/README.md b/README.md index e5a7942..144b0b5 100644 --- a/README.md +++ b/README.md @@ -136,8 +136,7 @@ in this package: * **[Arrays Collections](docs/ArraysCollection.md):** a collection that only stores items that are arrays (i.e. items for which is_array is true) * **[Callables Collections](docs/CallablesCollections.md):** a collection that only stores items that are callables (i.e. items for which is_callable is true) * **[Objects Collections](docs/ObjectsCollections.md):** a collection that only stores items that are objects (i.e. items for which is_object is true) - * **[Iterables Collections](docs/IterablesCollection.md):** a collection that only accepts - items that are objects for which [\is_iterable](https://www.php.net/manual/en/function.is-iterable) returns true. This type of collection does not accept [arrays](https://www.php.net/manual/en/language.types.array.php) which are also iterables but not objects. Use [Arrays Collections](docs/ArraysCollection.md) to store arrays or you could create a new collection class that accepts all iterables (both arrays & every other type for which **is_iterable** returns **true**) + * **[Non-Array Iterables Collections](docs/NonArrayIterablesCollection.md):** a collection that only accepts items that are objects for which [\is_iterable](https://www.php.net/manual/en/function.is-iterable) returns true. This type of collection does not accept [arrays](https://www.php.net/manual/en/language.types.array.php) which are also iterables but not objects. Use [Arrays Collections](docs/ArraysCollection.md) to store arrays or you could create a new collection class that accepts all iterables (both arrays & every other type for which **is_iterable** returns **true**) * **[Specific Objects Collections](docs/SpecificObjectsCollection.md):** a collection that only stores items that are instances of a specified class or any of its sub-classes * **[Resources Collections](docs/ResourcesCollections.md):** a collection that only stores items that are resources (i.e. items for which is_resource is true) * **[Scalars Collections](docs/ScalarsCollections.md):** a collection that only stores items that are scalars (i.e. items for which is_scalar is true) @@ -218,6 +217,7 @@ or its sub-classes in a collection and don't want to have to create a custom col * [Arrays Collections](docs/ArraysCollection.md): a collection that can only contain [arrays](http://php.net/manual/en/language.types.array.php) * [Callables Collections](docs/CallablesCollections.md): a collection that can only contain [callables](http://php.net/manual/en/language.types.callable.php) * [Objects Collections](docs/ObjectsCollections.md): a collection that can only contain [objects](http://php.net/manual/en/language.types.object.php) (any kind of object) + * [Non-Array Iterables Collections](docs/NonArrayIterablesCollection.md): a collection that can only contain items that are objects (but not [arrays](https://www.php.net/manual/en/language.types.array.php)) for which [\is_iterable](https://www.php.net/manual/en/function.is-iterable) returns true * [Specific Objects Collections](docs/SpecificObjectsCollection.md): a collection that can either contain only instances of a specified class or any of its sub-classes or any type of [object](http://php.net/manual/en/language.types.object.php) (just like [Objects Collections](docs/ObjectsCollections.md)) if no class is specified * [Resources Collections](docs/ResourcesCollections.md): a collection that can only contain [resources](http://php.net/manual/en/language.types.resource.php) * [Scalars Collections](docs/ScalarsCollections.md): a collection that can only scalar values. I.e. any of [booleans](http://php.net/manual/en/language.types.boolean.php), [floats](http://php.net/manual/en/language.types.float.php), [integers](http://php.net/manual/en/language.types.integer.php) or [strings](http://php.net/manual/en/language.types.string.php). It accepts any mix of scalars, e.g. ints, booleans, floats and strings can all be present in an instance of this type of collection. diff --git a/docs/IterablesCollection.md b/docs/NonArrayIterablesCollection.md similarity index 75% rename from docs/IterablesCollection.md rename to docs/NonArrayIterablesCollection.md index 0d9315a..7bb011d 100644 --- a/docs/IterablesCollection.md +++ b/docs/NonArrayIterablesCollection.md @@ -1,6 +1,6 @@ -# Iterables Collection +# Non-Array Iterables Collection -`\VersatileCollections\IterablesCollection` is a Collection class that only accepts +`\VersatileCollections\NonArrayIterablesCollection` is a Collection class that only accepts items that are objects for which [\is_iterable](https://www.php.net/manual/en/function.is-iterable) returns true. >NOTE: this collection will not accept items that are arrays (because an array is not an object, even though it is an iterable). @@ -9,7 +9,7 @@ Example Usage: ```php - $collection = new \VersatileCollections\IterablesCollection( + $collection = new \VersatileCollections\NonArrayIterablesCollection( new \ArrayObject(), new \SplDoublyLinkedList(), new \SplStack(), @@ -23,7 +23,7 @@ Example Usage: // OR - $collection = new \VersatileCollections\IterablesCollection( + $collection = new \VersatileCollections\NonArrayIterablesCollection( new \ArrayObject(), new \SplDoublyLinkedList(), new \SplStack(), @@ -37,7 +37,7 @@ Example Usage: // OR - $collection = new \VersatileCollections\IterablesCollection(); + $collection = new \VersatileCollections\NonArrayIterablesCollection(); $collection[] = new ArrayObject(); $collection[] = new SplDoublyLinkedList(); $collection[] = new SplStack(); @@ -49,6 +49,6 @@ Example Usage: $collection[] = new SplObjectStorage(); ``` -Use this type of collection if you want to only store objects that are iterable. +Use this type of collection if you want to only store objects (except php [arrays](https://www.php.net/manual/en/language.types.array.php)) that are iterable. You can even extend it and add other features in your extended class. diff --git a/src/IterablesCollection.php b/src/NonArrayIterablesCollection.php similarity index 95% rename from src/IterablesCollection.php rename to src/NonArrayIterablesCollection.php index 323dfda..a881fe7 100644 --- a/src/IterablesCollection.php +++ b/src/NonArrayIterablesCollection.php @@ -26,7 +26,7 @@ * * @author Rotimi Ade */ -class IterablesCollection extends ObjectsCollection +class NonArrayIterablesCollection extends ObjectsCollection { public function __construct(iterable ...$iterableObjects) { diff --git a/tests/IterablesCollectionTest.php b/tests/NonArrayIterablesCollectionTest.php similarity index 86% rename from tests/IterablesCollectionTest.php rename to tests/NonArrayIterablesCollectionTest.php index bbf0380..c25e5e4 100644 --- a/tests/IterablesCollectionTest.php +++ b/tests/NonArrayIterablesCollectionTest.php @@ -1,13 +1,13 @@ assertEquals($collection->count(), 10); - $collection2 = IterablesCollection::makeNew([ + $collection2 = NonArrayIterablesCollection::makeNew([ new \ArrayObject(), new \SplDoublyLinkedList(), new \SplStack(), @@ -44,7 +44,7 @@ public function testThatOnlyIterableObjectsCanBeInjectedIntoCollection() { ]); $this->assertEquals($collection2->count(), 10); - $collection3 = new \VersatileCollections\IterablesCollection(); + $collection3 = new \VersatileCollections\NonArrayIterablesCollection(); $this->assertEquals($collection3->count(), 0); $collection3[] = new \SplPriorityQueue(); $collection3['r'] = new \SplObjectStorage();