SyslogHandlerFactory::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 20
ccs 0
cts 6
cp 0
rs 9.9
cc 3
nc 2
nop 3
crap 12
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