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

Logger   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogger() 0 3 1
A getLogger() 0 7 2
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