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

ErrorLogHandlerFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 12 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
13
/**
14
 * @author  Alex Patterson <[email protected]>
15
 * @package Arp\LaminasMonolog\Factory\Handler
16
 */
17
final class ErrorLogHandlerFactory extends AbstractFactory
18
{
19
    /**
20
     * @param ContainerInterface $container
21
     * @param string             $requestedName
22
     * @param array<mixed>|null  $options
23
     *
24
     * @return ErrorLogHandler
25
     *
26
     * @throws ServiceNotCreatedException
27
     */
28
    public function __invoke(
29
        ContainerInterface $container,
30
        string $requestedName,
31
        array $options = null
32
    ): ErrorLogHandler {
33
        $options = $options ?? $this->getServiceOptions($container, $requestedName);
34
35
        return new ErrorLogHandler(
36
            isset($options['message_type']) ? (int)$options['message_type'] : ErrorLogHandler::OPERATING_SYSTEM,
37
            isset($options['level']) ? (int)$options['level'] : Logger::DEBUG,
38
            isset($options['bubble']) ? (bool)$options['bubble'] : true,
39
            isset($options['expand_new_lines']) ? (bool)$options['expand_new_lines'] : false
40
        );
41
    }
42
}
43