|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | /** |
4 | | - * @copyright Copyright (c) 2018 gameeapp.com <[email protected]> |
5 | | - * @author Pavel Janda <[email protected]> |
6 | | - * @package Gamee |
| 4 | + * @copyright Copyright (c) 2018 gameeapp.com <[email protected]> |
| 5 | + * |
| 6 | + * @author Pavel Janda <[email protected]> |
| 7 | + * |
| 8 | + * @package Gamee |
7 | 9 | */ |
8 | 10 |
|
9 | 11 | declare(strict_types=1); |
|
12 | 14 |
|
13 | 15 | use Gamee\Collections\Iterator\ObjectIterator; |
14 | 16 |
|
| 17 | +/** |
| 18 | + * @deprecated will be removed in 5.0, use UniqueObjectCollection |
| 19 | + */ |
15 | 20 | abstract class ImmutableObjectCollection extends ObjectIterator implements \Countable |
16 | 21 | { |
17 | | - |
18 | | - abstract protected function getItemType(): string; |
19 | | - |
20 | | - |
21 | | - final public function __construct(array $data) |
22 | | - { |
23 | | - $classItemName = $this->getItemType(); |
24 | | - |
25 | | - foreach ($data as $item) { |
26 | | - if (!$item instanceof $classItemName) { |
27 | | - throw new \InvalidArgumentException(self::class . ' only accepts ' . $this->getItemType()); |
28 | | - } |
29 | | - } |
30 | | - |
31 | | - parent::__construct($data); |
32 | | - } |
33 | | - |
34 | | - /** |
35 | | - * @param mixed $item |
36 | | - * |
37 | | - * @throws \InvalidArgumentException |
38 | | - */ |
39 | | - public function addItem($item): self |
40 | | - { |
41 | | - $classItemName = $this->getItemType(); |
42 | | - |
43 | | - if (!$item instanceof $classItemName) { |
44 | | - throw new \InvalidArgumentException(self::class . '::addItem() only accepts ' . $this->getItemType()); |
45 | | - } |
46 | | - |
47 | | - return new static(array_merge($this->data, [$item])); |
48 | | - } |
49 | | - |
50 | | - |
51 | | - public function count(): int |
52 | | - { |
53 | | - return count($this->data); |
54 | | - } |
55 | | - |
56 | | - |
57 | | - public function isEmpty(): bool |
58 | | - { |
59 | | - return $this->data === []; |
60 | | - } |
| 22 | + final public function __construct(array $data) |
| 23 | + { |
| 24 | + $classItemName = $this->getItemType(); |
| 25 | + |
| 26 | + foreach ($data as $item) { |
| 27 | + if (!$item instanceof $classItemName) { |
| 28 | + throw new \InvalidArgumentException(self::class . ' only accepts ' . $this->getItemType()); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + parent::__construct($data); |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | + abstract protected function getItemType(): string; |
| 37 | + |
| 38 | + |
| 39 | + /** |
| 40 | + * @throws \InvalidArgumentException |
| 41 | + */ |
| 42 | + public function addItem(mixed $item): self |
| 43 | + { |
| 44 | + $classItemName = $this->getItemType(); |
| 45 | + |
| 46 | + if (!$item instanceof $classItemName) { |
| 47 | + throw new \InvalidArgumentException(self::class . '::addItem() only accepts ' . $this->getItemType()); |
| 48 | + } |
| 49 | + |
| 50 | + return new static(\array_merge($this->data, [$item])); |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + public function count(): int |
| 55 | + { |
| 56 | + return \count($this->data); |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + public function isEmpty(): bool |
| 61 | + { |
| 62 | + return $this->data === []; |
| 63 | + } |
61 | 64 | } |
0 commit comments