Completed
Push — master ( b520c4...41a82a )
by Bjørn
02:59
created

LoggerTrait::logLn()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
crap 2.1481
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebPConvert\Convert\Converters\BaseTraits;
4
5
/**
6
 * Trait for providing logging capabilities.
7
 *
8
 * This trait is currently only used in the AbstractConverter class. It has been extracted into a
9
 * trait in order to bundle the methods concerning logging.
10
 *
11
 * @package    WebPConvert
12
 * @author     Bjørn Rosell <[email protected]>
13
 * @since      Class available since Release 2.0.0
14
 */
15
trait LoggerTrait
16
{
17
18
    /** @var \WebPConvert\Loggers\BaseLogger  The logger (or null if not set) */
19
    protected $logger;
20
21
    /**
22
     * Set logger
23
     *
24
     * @param   \WebPConvert\Loggers\BaseLogger $logger (optional)  $logger
25
     * @return  void
26
     */
27 33
    public function setLogger($logger = null)
28
    {
29 33
        $this->logger = $logger;
30 33
    }
31
32
    /**
33
     * Write a line to the logger.
34
     *
35
     * @param  string  $msg    The line to write.
36
     * @param  string  $style  (optional) Ie "italic" or "bold"
37
     * @return void
38
     */
39 12
    protected function logLn($msg, $style = '')
40
    {
41 12
        if (isset($this->logger)) {
42
            $this->logger->logLn($msg, $style);
43
        }
44 12
    }
45
46
    /**
47
     * New line
48
     *
49
     * @return  void
50
     */
51 3
    protected function ln()
52
    {
53 3
        if (isset($this->logger)) {
54
            $this->logger->ln();
55
        }
56 3
    }
57
58
    /**
59
     * Write to the logger, without newline
60
     *
61
     * @param  string  $msg    What to write.
62
     * @param  string  $style  (optional) Ie "italic" or "bold"
63
     * @return void
64
     */
65
    protected function log($msg, $style = '')
66
    {
67
        if (isset($this->logger)) {
68
            $this->logger->log($msg, $style);
69
        }
70
    }
71
}
72