LoggerTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 71
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getLogger() 0 8 2
A log() 0 4 1
A debug() 0 4 1
A info() 0 4 1
A warning() 0 4 1
A error() 0 4 1
1
<?php
2
3
namespace Libcast\AssetDistributor;
4
5
use Psr\Log\LoggerInterface;
6
use Psr\Log\LogLevel;
7
use Psr\Log\NullLogger;
8
9
trait LoggerTrait
10
{
11
    /**
12
     *
13
     * @var LoggerInterface
14
     */
15
    protected $logger;
16
17
    /**
18
     *
19
     * @return LoggerInterface
20
     */
21
    protected function getLogger()
22
    {
23
        if (!$this->logger instanceof LoggerInterface) {
24
            $this->logger = new NullLogger;
25
        }
26
27
        return $this->logger;
28
    }
29
30
    /**
31
     *
32
     * @param string $message
33
     * @param array $context
34
     */
35
    public function log($message, $context = [], $level = LogLevel::DEBUG)
36
    {
37
        $this->getLogger()->log($level, $message, (array) $context);
38
    }
39
40
    /**
41
     *
42
     * @param string $message
43
     * @param array $context
44
     */
45
    public function debug($message, $context = [])
46
    {
47
        $this->log($message, $context);
48
    }
49
50
    /**
51
     *
52
     * @param string $message
53
     * @param array $context
54
     */
55
    public function info($message, $context = [])
56
    {
57
        $this->log($message, $context, LogLevel::INFO);
58
    }
59
60
    /**
61
     *
62
     * @param string $message
63
     * @param array $context
64
     */
65
    public function warning($message, $context = [])
66
    {
67
        $this->log($message, $context, LogLevel::WARNING);
68
    }
69
70
    /**
71
     *
72
     * @param string $message
73
     * @param array  $context
74
     */
75
    public function error($message, $context = [])
76
    {
77
        $this->log($message, $context, LogLevel::ERROR);
78
    }
79
}
80