Passed
Push — master ( 5339df...fb5d3c )
by Alexander
03:17
created

Message::withMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Queue\Message;
6
7
final class Message implements MessageInterface
8
{
9
    /**
10
     * @param mixed $data Message data, encodable by a queue adapter
11
     * @param array $metadata Message metadata, encodable by a queue adapter
12
     * @param string|null $id Message id
13
     */
14 85
    public function __construct(
15
        private string $handlerName,
16
        private mixed $data,
17
        private array $metadata = [],
18
    ) {
19 85
    }
20
21 28
    public function getHandlerName(): string
22
    {
23 28
        return $this->handlerName;
24
    }
25
26 44
    public function getData(): mixed
27
    {
28 44
        return $this->data;
29
    }
30
31 40
    public function getMetadata(): array
32
    {
33 40
        return $this->metadata;
34
    }
35
36 2
    public function withMetadata(array $metadata): self
37
    {
38 2
        $instance = clone $this;
39 2
        $instance->metadata = $metadata;
40
41 2
        return $instance;
42
    }
43
}
44