Total Complexity | 6 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
1 | <?php |
||
10 | class Container implements ContainerInterface |
||
11 | { |
||
12 | protected array $data = []; |
||
13 | |||
14 | /** |
||
15 | * Sets data |
||
16 | * --------- |
||
17 | * Устанавливает данные |
||
18 | * |
||
19 | * @param array $data |
||
20 | */ |
||
21 | public function __construct(array $data) |
||
22 | { |
||
23 | $this->data = $data; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Receives data |
||
28 | * ------------- |
||
29 | * Получает данные |
||
30 | * |
||
31 | * @param string|null $id |
||
32 | * @return void |
||
33 | */ |
||
34 | public function get(string $id = null) |
||
35 | { |
||
36 | if (empty($id)) { |
||
37 | return $this->data; |
||
|
|||
38 | } |
||
39 | |||
40 | if (!array_key_exists($id, $this->data)) { |
||
41 | throw new \InvalidArgumentException("'$id' is not isset"); |
||
42 | } |
||
43 | |||
44 | return $this->data[$id]; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Adds data |
||
49 | * --------- |
||
50 | * Добавляет данные |
||
51 | * |
||
52 | * @param string $id |
||
53 | * @param array $data |
||
54 | * @return void |
||
55 | */ |
||
56 | public function set(string $id, array $data): void |
||
57 | { |
||
58 | $this->data = array_merge($this->data, $data); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Checks for data |
||
63 | * --------------- |
||
64 | * Проверяет наличие данных |
||
65 | * |
||
66 | * @param string $id |
||
67 | * @return boolean |
||
68 | */ |
||
69 | public function has(string $id): bool |
||
72 | } |
||
73 | } |
||
74 |