| Total Complexity | 11 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class Base { |
||
| 6 | protected array $_extraArgs = []; |
||
| 7 | |||
| 8 | 67 | public function __construct(array $args = []) |
|
| 9 | { |
||
| 10 | 67 | $this->setState($args); |
|
| 11 | } |
||
| 12 | |||
| 13 | 67 | protected function setState(array $args = []): void |
|
| 14 | { |
||
| 15 | 67 | foreach ($args as $key => $value) { |
|
| 16 | 63 | $property = "_{$key}"; |
|
| 17 | |||
| 18 | 63 | if (property_exists($this, $property)) { |
|
| 19 | 26 | $this->{$property} = $value; |
|
| 20 | } else { |
||
| 21 | 52 | $this->_extraArgs[$key] = $value; |
|
| 22 | } |
||
| 23 | } |
||
| 24 | } |
||
| 25 | |||
| 26 | 6 | public function __call(string $name, array $args = []): mixed |
|
| 27 | { |
||
| 28 | 6 | $property = "_{$name}"; |
|
| 29 | |||
| 30 | 6 | if (property_exists($this, $property)) { |
|
| 31 | 4 | return $this->{$property}; |
|
| 32 | } |
||
| 33 | |||
| 34 | 2 | if (isset($this->_extraArgs[$name])) { |
|
| 35 | 2 | return $this->_extraArgs[$name]; |
|
| 36 | } |
||
| 37 | |||
| 38 | 1 | return false; |
|
| 39 | } |
||
| 40 | |||
| 41 | 17 | public function parseArgs(array $args = [], array $defaults = []): array |
|
| 42 | { |
||
| 43 | 17 | foreach ($defaults as $key => $value) { |
|
| 44 | 17 | if (!isset($args[$key])) { |
|
| 45 | 17 | $args[$key] = $value; |
|
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | 17 | return $args; |
|
| 50 | } |
||
| 51 | |||
| 52 | 9 | public function extraArgs(): array |
|
| 55 | } |
||
| 56 | } |