Completed
Push — 57-formatter-per-extension ( 73b3c8 )
by Nicolas
40:17 queued 36:16
created

LoggerAware   B

Complexity

Total Complexity 40

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 40
lcom 0
cbo 0
dl 0
loc 32
rs 8.2609

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogger() 0 6 1
A error() 0 4 1
A warning() 0 4 1
A info() 0 4 1
A debug() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like LoggerAware often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use LoggerAware, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Karma\Logging;
4
5
use Psr\Log\LoggerInterface;
6
7
trait LoggerAware
8
{
9
    private
10
        $logger;
11
    
12
    public function setLogger(LoggerInterface $logger)
13
    {
14
        $this->logger = $logger;
15
    
16
        return $this;
17
    }
18
    
19
    private function error($message)
20
    {
21
        return $this->logger->error($message);
22
    }
23
    
24
    private function warning($message)
25
    {
26
        return $this->logger->warning($message);
27
    }    
28
    
29
    private function info($message)
30
    {
31
        return $this->logger->info($message);
32
    }
33
    
34
    private function debug($message)
35
    {
36
        return $this->logger->debug($message);
37
    }
38
}