Passed
Pull Request — master (#14)
by Camilo
01:32
created

ProtocolBase::hasActivePacketIdentifier()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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 said class. However, the method does not exist in Psr\Log\AbstractLogger or Psr\Log\NullLogger. Are you sure you never get one of those? ( 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 overwrite this method
36
     */
37 127
    protected function initializeObject(): ProtocolBase
38
    {
39 127
        return $this;
40
    }
41
42
    /**
43
     * If the object in question uses Packet Identifier functionality, it should be added to the stack
44
     */
45
    final public function hasActivePacketIdentifier(): bool
46
    {
47
        return property_exists($this, 'packetIdentifier') && $this->packetIdentifier !== null;
48
    }
49
}
50