Passed
Push — master ( c1f248...257530 )
by Camilo
01:51
created

SimplePayload   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 76.47%

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 46
c 0
b 0
f 0
ccs 13
cts 17
cp 0.7647
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A processIncomingPayload() 0 3 1
A setPayload() 0 5 1
A __construct() 0 10 3
A getProcessedPayload() 0 3 1
A getPayload() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace unreal4u\MQTT\Application;
6
7
use Psr\Log\LoggerInterface;
8
use unreal4u\MQTT\DummyLogger;
9
10
/**
11
 * The most basic functionality: send the payload as-is provided, without any additional processing on the data
12
 */
13
final class SimplePayload implements PayloadInterface
14
{
15
    /**
16
     * The contents of the payload itself
17
     * @var string
18
     */
19
    private $payload = '';
20
21
    /**
22
     * @var LoggerInterface
23
     */
24
    private $logger;
25
26 14
    public function __construct(string $messageContents = null, LoggerInterface $logger = null)
27
    {
28
        // Set the logger before setting the payload so that we already have it in the object
29 14
        if ($logger === null) {
30 14
            $logger = new DummyLogger();
31
        }
32 14
        $this->logger = $logger;
33
34 14
        if ($messageContents !== null) {
35 14
            $this->setPayload($messageContents);
36
        }
37 14
    }
38
39 14
    public function setPayload(string $contents): PayloadInterface
40
    {
41 14
        $this->payload = $contents;
42 14
        $this->logger->debug('Setting contents of payload', ['contents' => $contents]);
43 14
        return $this;
44
    }
45
46
    public function getPayload(): string
47
    {
48
        return $this->payload;
49
    }
50
51
    public function processIncomingPayload(string $contents): PayloadInterface
52
    {
53
        return $this;
54
    }
55
56 7
    public function getProcessedPayload(): string
57
    {
58 7
        return $this->payload;
59
    }
60
}
61