FormatterContainerTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormatter() 0 8 2
A setFormatter() 0 4 1
A getFormattedMessage() 0 4 1
A getDefaultFormatter() 0 4 1
1
<?php
2
3
namespace Oqq\Minc\Log\Formatter;
4
5
use Oqq\Minc\Log\Record;
6
7
/**
8
 * @author Eric Braun <[email protected]>
9
 */
10
trait FormatterContainerTrait
11
{
12
    /** @var FormatterInterface */
13
    protected $formatter;
14
15
    /**
16
     * @return FormatterInterface
17
     */
18 12
    public function getFormatter()
19
    {
20 12
        if (null === $this->formatter) {
21 1
            $this->formatter = $this->getDefaultFormatter();
22 1
        }
23
24 12
        return $this->formatter;
25 1
    }
26
27
    /**
28
     * @param FormatterInterface $formatter
29
     */
30 16
    public function setFormatter(FormatterInterface $formatter)
31
    {
32 16
        $this->formatter = $formatter;
33 16
    }
34
35
    /**
36
     * @param Record $record
37
     *
38
     * @return string
39
     */
40 10
    public function getFormattedMessage(Record $record)
41
    {
42 10
        return $this->getFormatter()->format($record);
43
    }
44
45
    /**
46
     * @return LineFormatter
47
     */
48 1
    protected function getDefaultFormatter()
49
    {
50 1
        return new LineFormatter();
51
    }
52
}
53