| Total Complexity | 6 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | class DbHandler extends AbstractProcessingHandler |
||
| 20 | { |
||
| 21 | private LogRepository $logRepository; |
||
| 22 | |||
| 23 | private bool $enabled = false; |
||
| 24 | |||
| 25 | 2 | public function __construct( |
|
| 26 | /** |
||
| 27 | * @var Closure(): LogRepository |
||
| 28 | */ |
||
| 29 | private readonly Closure $logRepositoryGetter, |
||
| 30 | ) { |
||
| 31 | 2 | parent::__construct(Level::Info); |
|
| 32 | } |
||
| 33 | |||
| 34 | 2 | public function isHandling(LogRecord $record): bool |
|
| 35 | { |
||
| 36 | 2 | return $this->enabled && parent::isHandling($record); |
|
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Write a message to the DB. |
||
| 41 | */ |
||
| 42 | 1 | protected function write(LogRecord $record): void |
|
| 43 | { |
||
| 44 | 1 | if (!isset($this->logRepository)) { |
|
| 45 | 1 | $this->logRepository = $this->logRepositoryGetter->__invoke(); |
|
| 46 | } |
||
| 47 | |||
| 48 | 1 | $this->logRepository->log($record); |
|
| 49 | } |
||
| 50 | |||
| 51 | 1 | public function enable(): void |
|
| 54 | } |
||
| 55 | } |
||
| 56 |