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 | 14 | final public function __construct(iterable $items) |
|
16 | { |
||
17 | 14 | $this->items = $items instanceof \Traversable ? iterator_to_array($items) : $items; |
|
18 | 14 | $this->assertType(); |
|
19 | 13 | } |
|
20 | |||
21 | 3 | public function getItems(): array |
|
22 | { |
||
23 | 3 | return $this->items; |
|
24 | } |
||
25 | |||
26 | 5 | public function count(): int |
|
29 | } |
||
30 | |||
31 | 4 | public function isEmpty(): bool |
|
34 | } |
||
35 | |||
36 | 4 | public function makeSureNotEmpty(): void |
|
37 | { |
||
38 | 4 | if ($this->isEmpty()) { |
|
39 | 1 | throw CollectionException::emptyCollection(); |
|
40 | } |
||
41 | 3 | } |
|
42 | |||
43 | 8 | public function filter(callable $filter): static |
|
44 | { |
||
45 | 8 | return new static(array_filter($this->items, $filter)); |
|
46 | } |
||
47 | |||
48 | 10 | public function getIterator(): \ArrayIterator |
|
51 | } |
||
52 | |||
53 | abstract protected function getType(): string; |
||
54 | |||
55 | 14 | private function assertType(): void |
|
61 | } |
||
62 | 13 | } |
|
63 | } |
||
64 |