WebProcessorFactory::getServerDataService()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 21

Duplication

Lines 20
Ratio 95.24 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 20
loc 21
ccs 10
cts 10
cp 1
rs 9.2728
c 0
b 0
f 0
cc 5
nc 4
nop 1
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WShafer\PSR11MonoLog\Processor;
6
7
use ArrayAccess;
8
use Monolog\Processor\WebProcessor;
9
use WShafer\PSR11MonoLog\ContainerAwareInterface;
10
use WShafer\PSR11MonoLog\ContainerTrait;
11
use WShafer\PSR11MonoLog\Exception\MissingServiceException;
12
use WShafer\PSR11MonoLog\FactoryInterface;
13
14
class WebProcessorFactory implements FactoryInterface, ContainerAwareInterface
15
{
16
    use ContainerTrait;
17
18 1
    public function __invoke(array $options)
19
    {
20 1
        $serverData     = $this->getServerDataService($options);
21 1
        $extraFields    = $options['extraFields'] ?? null;
22
23 1
        return new WebProcessor(
24 1
            $serverData,
25 1
            $extraFields
26
        );
27
    }
28
29 6 View Code Duplication
    public function getServerDataService(array $options)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31 6
        if (empty($options['serverData'])) {
32 2
            return null;
33
        }
34
35
        if (
36 4
            is_array($options['serverData'])
37 4
            || $options['serverData'] instanceof ArrayAccess
38
        ) {
39 2
            return $options['serverData'];
40
        }
41
42 2
        if (!$this->getContainer()->has($options['serverData'])) {
43 1
            throw new MissingServiceException(
44 1
                'No serverData service found'
45
            );
46
        }
47
48 1
        return $this->getContainer()->get($options['serverData']);
49
    }
50
}
51