Issues (4)

src/Container.php (1 issue)

1
<?php
2
3
/**
4
 * @author    : Jagepard <[email protected]">
5
 * @license   https://mit-license.org/ MIT
6
 */
7
8
namespace Primate\Container;
9
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->data returns the type array which is incompatible with the documented return type void.
Loading history...
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
70
    {
71
        return array_key_exists($id, $this->data);
72
    }
73
}
74