Issues (9)

src/Observability/Traits/Logger.php (1 issue)

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