WebProcessorFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 54.05 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 20
loc 37
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 1
A getServerDataService() 20 21 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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