Logger::getLogger()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace RemotelyLiving\PHPDNS\Observability\Traits;
4
5
use Psr\Log\LoggerInterface;
6
use Psr\Log\NullLogger;
7
8
trait Logger
9
{
10
    private ?LoggerInterface $logger = null;
11
12
    public function setLogger(LoggerInterface $logger): void
13
    {
14
        $this->logger = $logger;
15
    }
16
17
    protected function getLogger(): LoggerInterface
18
    {
19
        if ($this->logger === null) {
20
            $this->logger = new NullLogger();
21
        }
22
23
        return $this->logger;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->logger could return the type null which is incompatible with the type-hinted return Psr\Log\LoggerInterface. Consider adding an additional type-check to rule them out.
Loading history...
24
    }
25
}
26