LogConverter::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4285
c 1
b 0
f 1
cc 2
eloc 5
nc 2
nop 3
crap 2
1
<?php
2
3
/**
4
 * This file is part of plumphp/plum.
5
 *
6
 * (c) Florian Eckerstorfer <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Plum\Plum\Converter;
12
13
use Psr\Log\LoggerInterface;
14
15
/**
16
 * LogConverter.
17
 *
18
 * @author    Florian Eckerstorfer <[email protected]>
19
 * @copyright 2014-2016 Florian Eckerstorfer
20
 */
21
class LogConverter implements ConverterInterface
22
{
23
    /**
24
     * @var LoggerInterface
25
     */
26
    protected $logger;
27
28
    /**
29
     * @var string
30
     */
31
    protected $level;
32
33
    /**
34
     * @var string
35
     */
36
    protected $message = 'Converting item';
37
38
    /**
39
     * @param LoggerInterface $logger
40
     * @param string          $level
41
     * @param string|null     $message
42
     */
43 2
    public function __construct(LoggerInterface $logger, $level = 'debug', $message = null)
44
    {
45 2
        $this->logger = $logger;
46 2
        $this->level  = $level;
47 2
        if ($message !== null) {
48 1
            $this->message = $message;
49 1
        }
50 2
    }
51
52
    /**
53
     * @param mixed $item
54
     *
55
     * @return mixed
56
     */
57 2
    public function convert($item)
58
    {
59 2
        $this->logger->log($this->level, $this->message, $item);
60
61 2
        return $item;
62
    }
63
}
64