← All changes
|
includes/sdk/google/ramsey/collection/src/Collection.php
+8
-16
1.0.0
→
1.4.1
View file →
| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> |
| 10 | 10 | * @license http://opensource.org/licenses/MIT MIT |
| 11 | 11 | */ |
| 12 | 12 | declare (strict_types=1); |
| 13 | -namespace Dudlewebs\WPMCS\Ramsey\Collection; | |
| 13 | +namespace Dudlewebs\WPMCS\GCP\Ramsey\Collection; | |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * A collection represents a group of objects. |
| 17 | 17 | * |
| @@ -21,9 +21,9 @@ | ||
| 21 | 21 | * the sake of convenience. |
| 22 | 22 | * |
| 23 | 23 | * Example usage: |
| 24 | 24 | * |
| 25 | - * ``` php | |
| 25 | + * ``` | |
| 26 | 26 | * $collection = new \Ramsey\Collection\Collection('My\\Foo'); |
| 27 | 27 | * $collection->add(new \My\Foo()); |
| 28 | 28 | * $collection->add(new \My\Foo()); |
| 29 | 29 | * |
| @@ -34,9 +34,9 @@ | ||
| 34 | 34 | * |
| 35 | 35 | * It is preferable to subclass `AbstractCollection` to create your own typed |
| 36 | 36 | * collections. For example: |
| 37 | 37 | * |
| 38 | - * ``` php | |
| 38 | + * ``` | |
| 39 | 39 | * namespace My\Foo; |
| 40 | 40 | * |
| 41 | 41 | * class FooCollection extends \Ramsey\Collection\AbstractCollection |
| 42 | 42 | * { |
| @@ -48,9 +48,9 @@ | ||
| 48 | 48 | * ``` |
| 49 | 49 | * |
| 50 | 50 | * And then use it similarly to the earlier example: |
| 51 | 51 | * |
| 52 | - * ``` php | |
| 52 | + * ``` | |
| 53 | 53 | * $fooCollection = new \My\Foo\FooCollection(); |
| 54 | 54 | * $fooCollection->add(new \My\Foo()); |
| 55 | 55 | * $fooCollection->add(new \My\Foo()); |
| 56 | 56 | * |
| @@ -61,9 +61,9 @@ | ||
| 61 | 61 | * |
| 62 | 62 | * The benefit with this approach is that you may do type-checking on the |
| 63 | 63 | * collection object: |
| 64 | 64 | * |
| 65 | - * ``` php | |
| 65 | + * ``` | |
| 66 | 66 | * if ($collection instanceof \My\Foo\FooCollection) { |
| 67 | 67 | * // the collection is a collection of My\Foo objects |
| 68 | 68 | * } |
| 69 | 69 | * ``` |
| @@ -73,28 +73,20 @@ | ||
| 73 | 73 | */ |
| 74 | 74 | class Collection extends AbstractCollection |
| 75 | 75 | { |
| 76 | 76 | /** |
| 77 | - * The type of elements stored in this collection. | |
| 78 | - * | |
| 79 | - * A collection's type is immutable once it is set. For this reason, this | |
| 80 | - * property is set private. | |
| 81 | - */ | |
| 82 | - private string $collectionType; | |
| 83 | - /** | |
| 84 | 77 | * Constructs a collection object of the specified type, optionally with the |
| 85 | 78 | * specified data. |
| 86 | 79 | * |
| 87 | - * @param string $collectionType The type (FQCN) associated with this | |
| 80 | + * @param string $collectionType The type or class name associated with this | |
| 88 | 81 | * collection. |
| 89 | 82 | * @param array<array-key, T> $data The initial items to store in the collection. |
| 90 | 83 | */ |
| 91 | - public function __construct(string $collectionType, array $data = []) | |
| 84 | + public function __construct(private readonly string $collectionType, array $data = []) | |
| 92 | 85 | { |
| 93 | - $this->collectionType = $collectionType; | |
| 94 | 86 | parent::__construct($data); |
| 95 | 87 | } |
| 96 | - public function getType(): string | |
| 88 | + public function getType() : string | |
| 97 | 89 | { |
| 98 | 90 | return $this->collectionType; |
| 99 | 91 | } |
| 100 | 92 | } |