Passed
Push — master ( d36af8...d37c8b )
by Camilo
02:15
created

ProtocolBase::initializeObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace unreal4u\MQTT\Internals;
6
7
use Psr\Log\LoggerInterface;
8
use unreal4u\Dummy\Logger;
9
10
abstract class ProtocolBase
11
{
12
    /**
13
     * The actual logger object
14
     * @var LoggerInterface
15
     */
16
    protected $logger;
17
18
    /**
19
     * Base constructor for all protocol stuff
20
     * @param LoggerInterface|null $logger
21
     */
22 127
    final public function __construct(LoggerInterface $logger = null)
23
    {
24 127
        if ($logger === null) {
25 127
            $logger = new Logger();
26
        }
27
28
        // Insert name of class within the logger
29 127
        $this->logger = $logger->withName(str_replace('unreal4u\\MQTT\\', '', \get_class($this)));
0 ignored issues
show
Bug introduced by
The method withName() does not exist on Psr\Log\LoggerInterface. It seems like you code against a sub-type of Psr\Log\LoggerInterface such as unreal4u\Dummy\Logger or Monolog\Logger. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        /** @scrutinizer ignore-call */ 
30
        $this->logger = $logger->withName(str_replace('unreal4u\\MQTT\\', '', \get_class($this)));
Loading history...
30
31 127
        $this->initializeObject();
32 127
    }
33
34
    /**
35
     * Should any method have any abnormal default behaviour, we can do so here
36
     *
37
     * @return ProtocolBase
38
     */
39 127
    protected function initializeObject(): ProtocolBase
40
    {
41 127
        return $this;
42
    }
43
}
44