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

LineFormatterFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 27
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 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