SyslogHandlerFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 26
ccs 0
cts 6
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 20 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasMonolog\Factory\Handler;
6
7
use Arp\LaminasFactory\AbstractFactory;
8
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
9
use Monolog\Handler\SyslogHandler;
10
use Monolog\Logger;
11
use Psr\Container\ContainerExceptionInterface;
12
use Psr\Container\ContainerInterface;
13
14
final class SyslogHandlerFactory extends AbstractFactory
15
{
16
    /**
17
     * @throws ServiceNotCreatedException
18
     * @throws ContainerExceptionInterface
19
     */
20
    public function __invoke(
21
        ContainerInterface $container,
22
        string $requestedName,
23
        array $options = null
24
    ): SyslogHandler {
25
        $options = $options ?? $this->getServiceOptions($container, $requestedName);
26
27
        $ident = $options['ident'] ?? '';
28
        if (empty($ident)) {
29
            throw new ServiceNotCreatedException(
30
                sprintf('The required \'ident\' configuration option is missing for service \'%s\'', $requestedName)
31
            );
32
        }
33
34
        return new SyslogHandler(
35
            $ident,
36
            $options['facility'] ?? LOG_USER,
37
            $options['level'] ?? Logger::DEBUG,
38
            !isset($options['bubble']) || (bool)$options['bubble'],
39
            $options['logopts'] ?? LOG_PID
40
        );
41
    }
42
}
43