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

Logger::setLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
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