| Total Complexity | 10 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 95.45% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | final class Logger |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array<string,array<integer,mixed>> |
||
| 11 | */ |
||
| 12 | private array $entries = []; |
||
| 13 | |||
| 14 | 117 | public function __construct() |
|
| 19 | ]; |
||
| 20 | 117 | } |
|
| 21 | |||
| 22 | 3 | public function error(string $message, array $context = []): void |
|
| 23 | { |
||
| 24 | 3 | $this->log('error', $message, $context); |
|
| 25 | 3 | } |
|
| 26 | |||
| 27 | 3 | public function warning(string $message, array $context = []): void |
|
| 28 | { |
||
| 29 | 3 | $this->log('warning', $message, $context); |
|
| 30 | 3 | } |
|
| 31 | |||
| 32 | 3 | private function log($level, $message, array $context = []): void |
|
| 39 | 3 | } |
|
| 40 | |||
| 41 | 5 | public function getEntries(?string $level = null): array |
|
| 42 | { |
||
| 43 | 5 | if (null !== $level && isset($this->entries[$level])) { |
|
| 44 | 2 | return $this->entries[$level]; |
|
| 45 | 5 | } elseif (null == $level) { |
|
|
|
|||
| 46 | 3 | return $this->entries; |
|
| 47 | } |
||
| 48 | |||
| 49 | 2 | throw new Exception('Level '.$level.' not set.'); |
|
| 50 | } |
||
| 51 | |||
| 52 | 2 | public function hasEntries(?string $level = null): bool |
|
| 55 | } |
||
| 56 | } |
||
| 57 |