Total Complexity | 8 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
6 | class GenericEntity implements Entity, ArrayAccess |
||
7 | { |
||
8 | private $id; |
||
9 | private $idKey; |
||
10 | private $data; |
||
11 | |||
12 | public function __construct(array $data, string $idKey = 'id') |
||
13 | { |
||
14 | $this->idKey = $idKey; |
||
15 | |||
16 | $id = $data[$this->idKey] ?? null; |
||
17 | $this->id = new GenericId($id); |
||
18 | $this->data = $data; |
||
19 | } |
||
20 | |||
21 | public function getId(): \Igni\Storage\Id |
||
22 | { |
||
23 | return $this->id; |
||
24 | } |
||
25 | |||
26 | public function offsetExists($offset) |
||
27 | { |
||
28 | return isset($this->data[$offset]); |
||
29 | } |
||
30 | |||
31 | public function offsetGet($offset) |
||
32 | { |
||
33 | return $this->data[$offset] ?? null; |
||
34 | } |
||
35 | |||
36 | public function offsetSet($offset, $value) |
||
43 | } |
||
44 | |||
45 | public function offsetUnset($offset) |
||
52 | } |
||
53 | } |
||
54 |