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

ProtocolBase   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 32
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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