Completed
Push — master ( c1ddd1...39fcfb )
by Bjørn
03:00
created

LoggerTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 54
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogger() 0 3 1
A ln() 0 4 2
A logLn() 0 4 2
A log() 0 4 2
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 31
    public function setLogger($logger = null)
28
    {
29 31
        $this->logger = $logger;
30 31
    }
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 18
    protected function logLn($msg, $style = '')
40
    {
41 18
        if (isset($this->logger)) {
42 1
            $this->logger->logLn($msg, $style);
43
        }
44 18
    }
45
46
    /**
47
     * New line
48
     *
49
     * @return  void
50
     */
51 5
    protected function ln()
52
    {
53 5
        if (isset($this->logger)) {
54
            $this->logger->ln();
55
        }
56 5
    }
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 9
    protected function log($msg, $style = '')
66
    {
67 9
        if (isset($this->logger)) {
68 1
            $this->logger->log($msg, $style);
69
        }
70 9
    }
71
}
72