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

SimplePayload::getProcessedPayload()   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\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