FormatterContainerTrait::getFormattedMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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