ErrorLogHandlerFactory::__invoke()   A
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
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 2
cts 2
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
 * @phpstan-import-type Level from \Monolog\Logger
17
 * @phpstan-import-type LevelName from \Monolog\Logger
18
 */
19
final class ErrorLogHandlerFactory extends AbstractFactory
20
{
21
    /**
22
     * @throws ServiceNotCreatedException
23
     * @throws ContainerExceptionInterface
24
     */
25
    public function __invoke(
26
        ContainerInterface $container,
27
        string $requestedName,
28
        array $options = null
29
    ): ErrorLogHandler {
30
        $options = $options ?? $this->getServiceOptions($container, $requestedName);
31
32
        /** @var Level|LevelName|LogLevel::* $level */
33
        $level = isset($options['level']) ? (int)$options['level'] : Logger::DEBUG;
34 1
35
        return new ErrorLogHandler(
36
            isset($options['message_type']) ? (int)$options['message_type'] : ErrorLogHandler::OPERATING_SYSTEM,
37
            $level,
38
            !isset($options['bubble']) || $options['bubble'],
39 1
            isset($options['expand_new_lines']) && $options['expand_new_lines']
40
        );
41
    }
42
}
43