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

LineFormatterFactory::__invoke()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.9666
cc 4
nc 1
nop 3
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasMonolog\Factory\Formatter;
6
7
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
8
use Monolog\Formatter\LineFormatter;
9
use Psr\Container\ContainerExceptionInterface;
10
use Psr\Container\ContainerInterface;
11
12
/**
13
 * Create a new LineFormatter instance based on configuration options
14
 *
15
 * @author  Alex Patterson <[email protected]>
16
 * @package Arp\LaminasMonolog\Factory\Formatter
17
 */
18
final class LineFormatterFactory extends AbstractNormalizerFormatterFactory
19
{
20
    /**
21
     * @param ContainerInterface $container
22
     * @param string             $requestedName
23
     * @param array<mixed>|null  $options
24
     *
25
     * @return LineFormatter
26
     *
27
     * @throws ServiceNotCreatedException
28
     * @throws ContainerExceptionInterface
29
     */
30 4
    public function __invoke(ContainerInterface $container, string $requestedName, array $options = null): LineFormatter
31
    {
32 4
        $options = $options ?? $this->getServiceOptions($container, $requestedName);
33
34 4
        $formatter = new LineFormatter(
35 4
            $options['format'] ?? null,
36 4
            $options['date_format'] ?? null,
37 4
            isset($options['allow_inline_line_breaks']) && $options['allow_inline_line_breaks'],
38 4
            isset($options['ignore_empty_context_and_extra']) && $options['ignore_empty_context_and_extra'],
39 4
            isset($options['include_stack_traces']) && $options['include_stack_traces']
40
        );
41
42 4
        $this->configureNormalizerFormatter($formatter, $options);
43
44 4
        return $formatter;
45
    }
46
}
47