ChannelConfig   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 40
loc 40
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A validateConfig() 14 14 3
A getHandlers() 4 4 1
A getProcessors() 4 4 1
A getName() 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\Exception\MissingConfigException;
8
9 View Code Duplication
class ChannelConfig
10
{
11
    protected $config = [];
12
13 8
    public function __construct(array $config)
14
    {
15 8
        $this->validateConfig($config);
16 8
        $this->config = $config;
17 8
    }
18
19 8
    protected function validateConfig($config)
20
    {
21 8
        if (empty($config)) {
22 1
            throw new MissingConfigException(
23 1
                'No config found'
24
            );
25
        }
26
27 8
        if (empty($config['handlers'])) {
28 1
            throw new MissingConfigException(
29 1
                'No config key of "handlers" found in channel config array.'
30
            );
31
        }
32 8
    }
33
34 1
    public function getHandlers()
35
    {
36 1
        return $this->config['handlers'];
37
    }
38
39 2
    public function getProcessors()
40
    {
41 2
        return $this->config['processors'] ?? [];
42
    }
43
44 2
    public function getName()
45
    {
46 2
        return $this->config['name'] ?? null;
47
    }
48
}
49