Passed
Pull Request — master (#1)
by Alex
08:35
created

SyslogHandlerFactory::__invoke()   A

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 11
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\ContainerInterface;
12
13
/**
14
 * @author  Alex Patterson <[email protected]>
15
 * @package Arp\LaminasMonolog\Factory\Handler
16
 */
17
final class SyslogHandlerFactory extends AbstractFactory
18
{
19
    /**
20
     * @param ContainerInterface $container
21
     * @param string             $requestedName
22
     * @param array<mixed>|null  $options
23
     *
24
     * @return SyslogHandler
25
     *
26
     * @throws ServiceNotCreatedException
27
     */
28
    public function __invoke(
29
        ContainerInterface $container,
30
        string $requestedName,
31
        array $options = null
32
    ): SyslogHandler {
33
        $options = $options ?? $this->getServiceOptions($container, $requestedName);
34
35
        $ident = $options['ident'] ?? '';
36
        if (empty($ident)) {
37
            throw new ServiceNotCreatedException(
38
                sprintf('The required \'ident\' configuration option is missing for service \'%s\'', $requestedName)
39
            );
40
        }
41
42
        return new SyslogHandler(
43
            $ident,
44
            $options['facility'] ?? LOG_USER,
45
            $options['level'] ?? Logger::DEBUG,
46
            isset($options['bubble']) ? (bool)$options['bubble'] : true,
47
            $options['logopts'] ?? LOG_PID
48
        );
49
    }
50
}
51