Total Complexity | 10 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | class BaseConfig |
||
6 | { |
||
7 | protected $data = []; |
||
8 | |||
9 | public function __construct(Params $params) |
||
10 | { |
||
11 | $this->configure($params->get(static::class, [])); |
||
12 | } |
||
13 | |||
14 | public function __get($name) |
||
15 | { |
||
16 | $getter = 'get' . ucfirst($name); |
||
17 | return method_exists($this, $getter) ? $this->$getter() : ($this->data[$name] ?? null); |
||
18 | } |
||
19 | |||
20 | public function __set($name, $value): void |
||
21 | { |
||
22 | $setter = 'set' . ucfirst($name); |
||
23 | if (method_exists($this, $setter)) { |
||
24 | $this->$setter($value); |
||
25 | } elseif (key_exists($name, $this->data)) { |
||
26 | $this->data[$name] = $value; |
||
27 | } |
||
28 | } |
||
29 | |||
30 | public function configure(array $params): void |
||
34 | } |
||
35 | } |
||
36 | |||
37 | public function toArray(): array |
||
44 | } |
||
45 | } |
||
46 |