Passed
Pull Request — master (#1)
by Alex
02:54
created

ErrorLogHandlerFactory::__invoke()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.6111
cc 5
nc 2
nop 3
crap 5
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\ErrorLogHandler;
10
use Monolog\Logger;
11
use Psr\Container\ContainerExceptionInterface;
12
use Psr\Container\ContainerInterface;
13
use Psr\Log\LogLevel;
14
15
/**
16
 * @author  Alex Patterson <[email protected]>
17
 * @package Arp\LaminasMonolog\Factory\Handler
18
 *
19
 * @phpstan-import-type Level from \Monolog\Logger
20
 * @phpstan-import-type LevelName from \Monolog\Logger
21
 */
22
final class ErrorLogHandlerFactory extends AbstractFactory
23
{
24
    /**
25
     * @param ContainerInterface $container
26
     * @param string             $requestedName
27
     * @param array<mixed>|null  $options
28
     *
29
     * @return ErrorLogHandler
30
     *
31
     * @throws ServiceNotCreatedException
32
     * @throws ContainerExceptionInterface
33
     */
34 1
    public function __invoke(
35
        ContainerInterface $container,
36
        string $requestedName,
37
        array $options = null
38
    ): ErrorLogHandler {
39 1
        $options = $options ?? $this->getServiceOptions($container, $requestedName);
40
41
        /** @var Level|LevelName|LogLevel::* $level */
42 1
        $level = isset($options['level']) ? (int)$options['level'] : Logger::DEBUG;
43
44 1
        return new ErrorLogHandler(
45 1
            isset($options['message_type']) ? (int)$options['message_type'] : ErrorLogHandler::OPERATING_SYSTEM,
46
            $level,
47 1
            !isset($options['bubble']) || $options['bubble'],
48 1
            isset($options['expand_new_lines']) && $options['expand_new_lines']
49
        );
50
    }
51
}
52