Total Complexity | 9 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | trait KeyValueList |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $elements = []; |
||
16 | |||
17 | public function set($id, $value): void |
||
18 | { |
||
19 | $this->elements[$id] = $value; |
||
20 | } |
||
21 | |||
22 | public function get($id) |
||
23 | { |
||
24 | if (!$this->has($id)) { |
||
25 | throw NotFoundException::noEntryWasFound((string) $id); |
||
26 | } |
||
27 | |||
28 | return $this->elements[$id]; |
||
29 | } |
||
30 | |||
31 | public function has($id): bool |
||
34 | } |
||
35 | |||
36 | public function delete($id): void |
||
39 | } |
||
40 | |||
41 | public function getIterator(): Generator |
||
42 | { |
||
43 | foreach ($this->elements as $id => $element) { |
||
44 | yield $id => $element; |
||
45 | } |
||
46 | } |
||
47 | |||
48 | public function count(): int |
||
51 | } |
||
52 | |||
53 | public function isEmpty(): bool |
||
58 |