Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Config | |
100.00% |
12 / 12 |
|
100.00% |
4 / 4 |
8 | |
100.00% |
1 / 1 |
| get | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| set | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| has | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| remove | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Engelsystem\Config; |
| 4 | |
| 5 | use Illuminate\Support\Fluent; |
| 6 | |
| 7 | class Config extends Fluent |
| 8 | { |
| 9 | /** |
| 10 | * The config values |
| 11 | */ |
| 12 | protected $attributes = []; // phpcs:ignore |
| 13 | |
| 14 | /** |
| 15 | * @param string|array $key |
| 16 | */ |
| 17 | public function get(mixed $key, mixed $default = null): mixed |
| 18 | { |
| 19 | if (is_null($key)) { |
| 20 | return $this->attributes; |
| 21 | } |
| 22 | |
| 23 | if ($this->has($key)) { |
| 24 | return $this->attributes[$key]; |
| 25 | } |
| 26 | |
| 27 | return $default; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @param string|array $key |
| 32 | */ |
| 33 | public function set(mixed $key, mixed $value = null): void |
| 34 | { |
| 35 | if (is_array($key)) { |
| 36 | foreach ($key as $configKey => $configValue) { |
| 37 | $this->set($configKey, $configValue); |
| 38 | } |
| 39 | |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | $this->attributes[$key] = $value; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @param string $key |
| 48 | */ |
| 49 | public function has(mixed $key): bool |
| 50 | { |
| 51 | return $this->offsetExists($key); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @param string $key |
| 56 | */ |
| 57 | public function remove(mixed $key): void |
| 58 | { |
| 59 | $this->offsetUnset($key); |
| 60 | } |
| 61 | } |