LogTrait   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 59
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setLog() 0 4 1
A getLog() 0 4 1
A emergency() 0 4 1
A alert() 0 4 1
A critical() 0 4 1
A error() 0 4 1
A warning() 0 4 1
A notice() 0 4 1
A info() 0 4 1
A debug() 0 4 1
A log() 0 4 1
1
<?php
2
3
namespace Nopolabs\Yabot\Helpers;
4
5
6
use Psr\Log\LoggerInterface;
7
use Psr\Log\NullLogger;
8
9
trait LogTrait
10
{
11
    private $log;
12
13
    protected function setLog(LoggerInterface $log = null)
14
    {
15
        $this->log = $log ?? new NullLogger();
16
    }
17
18
    protected function getLog() : LoggerInterface
19
    {
20
        return $this->log;
21
    }
22
23
    protected function emergency($message, array $context = array())
24
    {
25
        $this->getLog()->emergency($message, $context);
26
    }
27
28
    protected function alert($message, array $context = array())
29
    {
30
        $this->getLog()->alert($message, $context);
31
    }
32
33
    protected function critical($message, array $context = array())
34
    {
35
        $this->getLog()->critical($message, $context);
36
    }
37
38
    protected function error($message, array $context = array())
39
    {
40
        $this->getLog()->error($message, $context);
41
    }
42
43
    protected function warning($message, array $context = array())
44
    {
45
        $this->getLog()->warning($message, $context);
46
    }
47
48
    protected function notice($message, array $context = array())
49
    {
50
        $this->getLog()->notice($message, $context);
51
    }
52
53
    protected function info($message, array $context = array())
54
    {
55
        $this->getLog()->info($message, $context);
56
    }
57
58
    protected function debug($message, array $context = array())
59
    {
60
        $this->getLog()->debug($message, $context);
61
    }
62
63
    protected function log($level, $message, array $context = array())
64
    {
65
        $this->getLog()->log($level, $message, $context);
66
    }
67
}