Passed
Pull Request — master (#214)
by Viktor
02:55
created

Message   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 40
ccs 10
cts 14
cp 0.7143
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getHandlerName() 0 3 1
A getMetadata() 0 3 1
A withMetadata() 0 6 1
A getData() 0 3 1
A fromData() 0 3 1
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 4
    public static function fromData(string $handlerName, mixed $data, array $metadata = []): MessageInterface
22
    {
23 4
        return new self($handlerName, $data, $metadata);
24
    }
25
26 28
    public function getHandlerName(): string
27
    {
28 28
        return $this->handlerName;
29
    }
30
31 44
    public function getData(): mixed
32
    {
33 44
        return $this->data;
34
    }
35
36 40
    public function getMetadata(): array
37
    {
38 40
        return $this->metadata;
39
    }
40
41
    public function withMetadata(array $metadata): self
42
    {
43
        $instance = clone $this;
44
        $instance->metadata = $metadata;
45
46
        return $instance;
47
    }
48
}
49