Passed
Pull Request — master (#3)
by De Cramer
07:09
created

LoggerContext   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 26
rs 10
c 2
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A finalise() 0 2 1
A replaceLoggerContext() 0 3 1
A getLogger() 0 6 2
A setLoggerContext() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Oliverde8\Component\PhpEtl\Model;
6
7
use oliverde8\AssociativeArraySimplified\AssociativeArray;
8
use Psr\Log\LoggerInterface;
9
use Psr\Log\NullLogger;
10
11
class LoggerContext
12
{
13
    protected array $loggerContext = [];
14
15
    protected ?LoggerInterface $logger = null;
16
17
    protected function setLoggerContext($key, $value)
18
    {
19
        AssociativeArray::setFromKey($loggerContext, $key, $value, ".");
20
    }
21
22
    protected function replaceLoggerContext(array $loggerContext): void
23
    {
24
        $this->loggerContext = $loggerContext;
25
    }
26
27
    public function getLogger(): LoggerInterface
28
    {
29
        if (is_null($this->logger)) {
30
            $this->logger = new NullLogger();
31
        }
32
        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...
33
    }
34
35
    protected function finalise(): void
36
    {
37
38
    }
39
}
40