AbstractHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A configure() 0 2 1
1
<?php
2
3
/*
4
 *  This file is part of the Micro framework package.
5
 *
6
 *  (c) Stanislau Komar <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace Micro\Plugin\Logger\Monolog\Business\Handler\Type;
13
14
use Micro\Component\DependencyInjection\Container;
15
use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface;
16
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerInterface;
17
use Micro\Plugin\Logger\Monolog\Configuration\Handler\HandlerConfigurationInterface;
18
use Monolog\Handler\AbstractProcessingHandler;
19
use Monolog\Level;
20
21
/**
22
 * @author Stanislau Komar <[email protected]>
23
 *
24
 * @codeCoverageIgnore
25
 */
26
abstract class AbstractHandler extends AbstractProcessingHandler implements HandlerInterface
27
{
28
    public function __construct(
29
        protected readonly Container $container,
30
        protected readonly HandlerConfigurationInterface $handlerConfiguration,
31
        protected readonly LoggerProviderTypeConfigurationInterface $loggerProviderTypeConfiguration
32
    ) {
33
        $levelName = mb_strtoupper($loggerProviderTypeConfiguration->getLogLevel()->level());
34
35
        if (!\in_array($levelName, Level::NAMES, true)) {
0 ignored issues
show
Bug introduced by
The constant Monolog\Level::NAMES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
36
            throw new \RuntimeException(sprintf('Invalid log level `%s` for the logger name `%s`.', $levelName, $this->loggerProviderTypeConfiguration->getLoggerName()));
37
        }
38
39
        $monoLevel = Level::fromName($levelName);
40
41
        parent::__construct($monoLevel);
42
43
        $this->configure();
44
    }
45
46
    public function configure(): void
47
    {
48
    }
49
}
50