Test Failed
Pull Request — master (#188)
by Dmitriy
02:40
created

IdEnvelope   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 25
ccs 6
cts 8
cp 0.75
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A __construct() 0 4 1
A setId() 0 3 1
A getEnvelopeMetadata() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Queue\Message;
6
7
/**
8
 * ID envelope allows to identify a message.
9
 */
10
final class IdEnvelope implements EnvelopeInterface
11
{
12
    use EnvelopeTrait;
13
14
    public const MESSAGE_ID_KEY = 'yii-message-id';
15
16 9
    public function __construct(
17
        private MessageInterface $message,
18
        private string|int|null $id = null,
19
    ) {
20 9
    }
21
22
    public function setId(string|int|null $id): void
23
    {
24
        $this->id = $id;
25
    }
26
27 8
    public function getId(): string|int|null
28
    {
29 8
        return $this->id ?? $this->message->getMetadata()[self::MESSAGE_ID_KEY] ?? null;
30
    }
31
32 8
    public function getEnvelopeMetadata(): array
33
    {
34 8
        return [self::MESSAGE_ID_KEY => $this->getId()];
35 8
    }
36
}
37