| Total Complexity | 11 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | abstract class Collection implements \IteratorAggregate, \Countable |
||
| 12 | { |
||
| 13 | protected array $items; |
||
| 14 | |||
| 15 | 21 | final public function __construct(iterable $items) |
|
| 16 | { |
||
| 17 | 21 | $this->items = $items instanceof \Traversable ? iterator_to_array($items) : $items; |
|
| 18 | 21 | $this->assertType(); |
|
| 19 | 20 | } |
|
| 20 | |||
| 21 | 7 | public function getItems(): array |
|
| 22 | { |
||
| 23 | 7 | return $this->items; |
|
| 24 | } |
||
| 25 | |||
| 26 | 11 | public function count(): int |
|
| 29 | } |
||
| 30 | |||
| 31 | 6 | public function isEmpty(): bool |
|
| 34 | } |
||
| 35 | |||
| 36 | 6 | public function makeSureNotEmpty(): void |
|
| 37 | { |
||
| 38 | 6 | if ($this->isEmpty()) { |
|
| 39 | 1 | throw CollectionException::emptyCollection(); |
|
| 40 | } |
||
| 41 | 5 | } |
|
| 42 | |||
| 43 | 12 | public function filter(callable $filter): static |
|
| 44 | { |
||
| 45 | 12 | return new static(array_filter($this->items, $filter)); |
|
| 46 | } |
||
| 47 | |||
| 48 | 12 | public function getIterator(): \ArrayIterator |
|
| 51 | } |
||
| 52 | |||
| 53 | abstract protected function getType(): string; |
||
| 54 | |||
| 55 | 21 | private function assertType(): void |
|
| 61 | } |
||
| 62 | 20 | } |
|
| 63 | } |
||
| 64 |