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

ErrorLogHandlerFactory::__invoke()   A

Complexity

Conditions 5
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
ccs 0
cts 7
cp 0
rs 9.6111
cc 5
nc 1
nop 3
crap 30
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