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

JsonFormatterFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
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\JsonFormatter;
9
use Psr\Container\ContainerExceptionInterface;
10
use Psr\Container\ContainerInterface;
11
12
/**
13
 * @author  Alex Patterson <[email protected]>
14
 * @package Arp\LaminasMonolog\Factory\Formatter
15
 */
16
final class JsonFormatterFactory extends AbstractNormalizerFormatterFactory
17
{
18
    /**
19
     * @param ContainerInterface $container
20
     * @param string             $requestedName
21
     * @param array<mixed>|null  $options
22
     *
23
     * @return JsonFormatter
24
     *
25
     * @throws ServiceNotCreatedException
26
     * @throws ContainerExceptionInterface
27
     */
28 5
    public function __invoke(ContainerInterface $container, string $requestedName, array $options = null): JsonFormatter
29
    {
30 5
        $options = $options ?? $this->getServiceOptions($container, $requestedName);
31
32 5
        $formatter = new JsonFormatter(
33 5
            $options['batch_mode'] ?? JsonFormatter::BATCH_MODE_JSON,
34 5
            $options['append_new_line'] ?? true,
35 5
            $options['ignore_empty_context_and_extra'] ?? false,
36 5
            $options['include_stack_traces'] ?? false,
37
        );
38
39 5
        $this->configureNormalizerFormatter($formatter, $options);
40
41 5
        return $formatter;
42
    }
43
}
44