Completed
Pull Request — master (#3)
by Christian
03:42 queued 01:29
created

Logger::getLogger()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
namespace RemotelyLiving\PHPDNS\Observability\Traits;
3
4
use Psr\Log\LoggerInterface;
5
use Psr\Log\NullLogger;
6
7
trait Logger
8
{
9
    /**
10
     * @var \Psr\Log\LoggerInterface
11
     */
12
    private $logger = null;
13
14
    public function setLogger(LoggerInterface $logger): void
15
    {
16
        $this->logger = $logger;
17
    }
18
19
    protected function getLogger(): LoggerInterface
20
    {
21
        if ($this->logger === null) {
22
            $this->logger = new NullLogger();
23
        }
24
25
        return $this->logger;
26
    }
27
}
28