LoggedClassTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogger() 0 4 1
A getLogger() 0 4 1
A updateLog() 0 12 2
1
<?php
2
namespace Subreality\Dilmun;
3
4
use Subreality\Dilmun\Nabu\Logger;
5
6
/**
7
 * Provides standard functions for interfacing a class with a Logger
8
 *
9
 * @package Subreality\Dilmun
10
 */
11
trait LoggedClassTrait
12
{
13
    /** @var  Logger */
14
    protected $logger;
15
16
    /**
17
     * Allows overriding the default file logger created at construction
18
     *
19
     * @param Logger $logger
20
     */
21 1
    public function setLogger(Logger $logger)
22
    {
23 1
        $this->logger = $logger;
24 1
    }
25
26
    /**
27
     * Gets the Logger set for the Autoloader
28
     *
29
     * @return Logger
30
     */
31 1
    public function getLogger()
32
    {
33 1
        return $this->logger;
34
    }
35
36
    /**
37
     * If it exists, logs the message at the supplied level using the set Logger
38
     *
39
     * @param string $level     The log level for the message
40
     * @param string $message   The message to be logged
41
     *
42
     * @return bool             Returns true if the message was logged
43
     *                          returns false if the message was not logged
44
     */
45 25
    protected function updateLog($level, $message, array $context = array())
46
    {
47 25
        if ($this->logger instanceof Logger) {
48 14
            $this->logger->$level($message, $context);
49
50 14
            $message_logged = true;
51 14
        } else {
52 19
            $message_logged = false;
53
        }
54
55 25
        return $message_logged;
56
    }
57
}
58