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

IdEnvelope::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
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