| Total Complexity | 13 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class Elements implements \Countable, \IteratorAggregate |
||
| 6 | { |
||
| 7 | /** @var ElementInterface[] elements */ |
||
| 8 | protected $elements = []; |
||
| 9 | |||
| 10 | public function add(ElementInterface $element) |
||
| 14 | } |
||
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param ElementInterface[] $elements |
||
| 19 | */ |
||
| 20 | public function addMulti(array $elements) |
||
| 21 | { |
||
| 22 | foreach ($elements as $element) { |
||
| 23 | $this->add($element); |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param ElementInterface $element |
||
| 29 | * @return false|int |
||
| 30 | */ |
||
| 31 | public function search(ElementInterface $element) |
||
| 32 | { |
||
| 33 | return array_search($element, $this->elements, true); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function remove(ElementInterface $element) |
||
| 37 | { |
||
| 38 | $id = $this->search($element); |
||
| 39 | if (false !== $id) { |
||
| 40 | unset($this->elements[$id]); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | public function exists(ElementInterface $element) |
||
| 45 | { |
||
| 46 | return (false !== $this->search($element)); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function getById(string $id): ElementInterface |
||
| 57 | } |
||
| 58 | |||
| 59 | public function count(): int |
||
| 60 | { |
||
| 61 | return count($this->elements); |
||
| 62 | } |
||
| 63 | |||
| 64 | public function getIterator() |
||
| 67 | } |
||
| 68 | } |
||
| 69 |