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

ErrorLogHandlerFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
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 26
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\ContainerInterface;
12
use Psr\Log\LogLevel;
13
14
/**
15
 * @author  Alex Patterson <[email protected]>
16
 * @package Arp\LaminasMonolog\Factory\Handler
17
 *
18
 * @phpstan-import-type Level from \Monolog\Logger
19
 * @phpstan-import-type LevelName from \Monolog\Logger
20
 */
21
final class ErrorLogHandlerFactory extends AbstractFactory
22
{
23
    /**
24
     * @param ContainerInterface $container
25
     * @param string             $requestedName
26
     * @param array<mixed>|null  $options
27
     *
28
     * @return ErrorLogHandler
29
     *
30
     * @throws ServiceNotCreatedException
31
     */
32 1
    public function __invoke(
33
        ContainerInterface $container,
34
        string $requestedName,
35
        array $options = null
36
    ): ErrorLogHandler {
37 1
        $options = $options ?? $this->getServiceOptions($container, $requestedName);
38
39
        /** @var Level|LevelName|LogLevel::* $level */
40 1
        $level = isset($options['level']) ? (int)$options['level'] : Logger::DEBUG;
41
42 1
        return new ErrorLogHandler(
43 1
            isset($options['message_type']) ? (int)$options['message_type'] : ErrorLogHandler::OPERATING_SYSTEM,
44
            $level,
45 1
            !isset($options['bubble']) || $options['bubble'],
46 1
            isset($options['expand_new_lines']) && $options['expand_new_lines']
47
        );
48
    }
49
}
50