Total Complexity | 10 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | trait KeyValueList |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $elements = []; |
||
15 | |||
16 | public function set($id, $value): void |
||
19 | } |
||
20 | |||
21 | public function get($id) |
||
22 | { |
||
23 | if (!$this->has($id)) { |
||
24 | throw new LogicException( |
||
25 | sprintf("[%s] Item not found (%s).", get_class($this), $id) |
||
26 | ); |
||
27 | } |
||
28 | |||
29 | return $this->elements[$id]; |
||
30 | } |
||
31 | |||
32 | public function has($id): bool |
||
33 | { |
||
34 | return array_key_exists($id, $this->elements); |
||
35 | } |
||
36 | |||
37 | public function delete($id): void |
||
38 | { |
||
39 | unset($this->elements[$id]); |
||
40 | } |
||
41 | |||
42 | public function getIterator(): Generator |
||
43 | { |
||
44 | foreach ($this->elements as $id => $element) { |
||
45 | yield $id => $element; |
||
46 | } |
||
47 | } |
||
48 | |||
49 | public function count(): int |
||
52 | } |
||
53 | |||
54 | public function isEmpty(): bool |
||
57 | } |
||
58 | |||
59 | public function toArray(): array |
||
60 | { |
||
64 |