| Total Complexity | 11 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class DataSource |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Associative data array by key pair value |
||
| 17 | * |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | private $data; |
||
| 21 | |||
| 22 | public function __construct(iterable $data = []) |
||
| 25 | } |
||
| 26 | |||
| 27 | public function getData(): array |
||
| 30 | } |
||
| 31 | |||
| 32 | public function setData(iterable $data): DataSource |
||
| 33 | { |
||
| 34 | $this->data = []; |
||
| 35 | |||
| 36 | foreach ($data as $key => $value) { |
||
| 37 | $this->setValue($key, $value); |
||
| 38 | } |
||
| 39 | |||
| 40 | return $this; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function addData(iterable $data): DataSource |
||
| 44 | { |
||
| 45 | foreach ($data as $key => $value) { |
||
| 46 | $this->setValue($key, $value); |
||
| 47 | } |
||
| 48 | |||
| 49 | return $this; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function getValue(string $key) |
||
| 53 | { |
||
| 54 | return $this->data[$key] ?? null; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function setValue(string $key, $value): DataSource |
||
| 58 | { |
||
| 59 | $this->data[$key] = $value; |
||
| 60 | |||
| 61 | return $this; |
||
| 62 | } |
||
| 63 | |||
| 64 | public function unsetValue(string $key): DataSource |
||
| 65 | { |
||
| 66 | unset($this->data[$key]); |
||
| 67 | |||
| 68 | return $this; |
||
| 69 | } |
||
| 70 | |||
| 71 | public function unsetValues(array $keys): DataSource |
||
| 78 | } |
||
| 79 | } |
||
| 80 |