Test Failed
Pull Request — master (#217)
by Viktor
03:25 queued 21s
created

IdEnvelope   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 24
ccs 5
cts 7
cp 0.7143
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A __construct() 0 5 1
A fromMessage() 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 extends AbstractEnvelope
11
{
12
    public const MESSAGE_ID_KEY = 'yii-message-id';
13
14
    public function __construct(
15
        MessageInterface $message,
16 13
        private readonly string|int|null $id = null,
17
    ) {
18
        parent::__construct($message);
19
    }
20 13
21
    public static function fromMessage(MessageInterface $message): self
22 2
    {
23
        return new self($message, $message->getMetadata()[self::MESSAGE_ID_KEY] ?? null);
24 2
    }
25
26
    public function getId(): string|int|null
27
    {
28
        return $this->id ?? $this->metadata[self::MESSAGE_ID_KEY] ?? null;
29
    }
30
31
    protected function getEnvelopeMetadata(): array
32 12
    {
33
        return [self::MESSAGE_ID_KEY => $this->getId()];
34 12
    }
35
}
36