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

ErrorLogHandlerFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 27
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 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