Message::setHeader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jellyfish\Queue;
6
7
use function array_key_exists;
8
9
class Message implements MessageInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $headers;
15
16
    /**
17
     * @var string
18
     */
19
    protected $body;
20
21
    public function __construct()
22
    {
23
        $this->headers = [];
24
    }
25
26
    /**
27
     * @return array
28
     */
29
    public function getHeaders(): array
30
    {
31
        return $this->headers;
32
    }
33
34
    /**
35
     * @param array $headers
36
     *
37
     * @return \Jellyfish\Queue\MessageInterface
38
     */
39
    public function setHeaders(array $headers): MessageInterface
40
    {
41
        $this->headers = $headers;
42
43
        return $this;
44
    }
45
46
    /**
47
     * @param string $key
48
     *
49
     * @return string|null
50
     */
51
    public function getHeader(string $key): ?string
52
    {
53
        if (!array_key_exists($key, $this->headers)) {
54
            return null;
55
        }
56
57
        return $this->headers[$key];
58
    }
59
60
    /**
61
     * @param string $key
62
     * @param string $value
63
     *
64
     * @return \Jellyfish\Queue\MessageInterface
65
     */
66
    public function setHeader(string $key, string $value): MessageInterface
67
    {
68
        $this->headers[$key] = $value;
69
70
        return $this;
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getBody(): string
77
    {
78
        return $this->body;
79
    }
80
81
    /**
82
     * @param string $body
83
     *
84
     * @return \Jellyfish\Queue\MessageInterface
85
     */
86
    public function setBody(string $body): MessageInterface
87
    {
88
        $this->body = $body;
89
90
        return $this;
91
    }
92
}
93