AbstractServiceConfig   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A validateConfig() 14 14 3
A getType() 4 4 1
A getOptions() 4 4 1

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\Config;
6
7
use WShafer\PSR11MonoLog\ConfigInterface;
8
use WShafer\PSR11MonoLog\Exception\MissingConfigException;
9
10 View Code Duplication
abstract class AbstractServiceConfig implements ConfigInterface
11
{
12
    protected $config = [];
13
14 21
    public function __construct(array $config)
15
    {
16 21
        $this->validateConfig($config);
17 21
        $this->config = $config;
18 21
    }
19
20 21
    protected function validateConfig($config)
21
    {
22 21
        if (empty($config)) {
23 3
            throw new MissingConfigException(
24 3
                'No config found'
25
            );
26
        }
27
28 21
        if (empty($config['type'])) {
29 3
            throw new MissingConfigException(
30 3
                'No config key of "type" found in adaptor config array.'
31
            );
32
        }
33 21
    }
34
35 3
    public function getType(): string
36
    {
37 3
        return $this->config['type'];
38
    }
39
40 6
    public function getOptions()
41
    {
42 6
        return $this->config['options'] ?? [];
43
    }
44
}
45