Loggable   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 35
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLogger() 0 4 1
A info() 0 6 2
A error() 0 6 2
1
<?php
2
/**
3
 * This file is part of Platform package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Karma\Platform\Support;
11
12
use Psr\Log\LoggerInterface;
13
14
/**
15
 * Trait Loggable
16
 * @package Karma\Platform\Support
17
 * @mixin LoggableInterface
18
 */
19
trait Loggable
20
{
21
    /**
22
     * @var null|LoggerInterface
23
     */
24
    protected $logger;
25
26
    /**
27
     * @return null|LoggerInterface
28
     */
29
    public function getLogger(): ?LoggerInterface
30
    {
31
        return $this->logger;
32
    }
33
34
    /**
35
     * @param string $message
36
     */
37
    public function info(string $message): void
38
    {
39
        if ($logger = $this->getLogger()) {
40
            $logger->info($message);
41
        }
42
    }
43
44
    /**
45
     * @param string $message
46
     */
47
    public function error(string $message): void
48
    {
49
        if ($logger = $this->getLogger()) {
50
            $logger->error($message);
51
        }
52
    }
53
}
54