Completed
Push — master ( 19ca72...4bd58a )
by Kirill
02:15
created

Loggable::getLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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