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 | 13 | public function __construct( |
|
17 | private MessageInterface $message, |
||
18 | private string|int|null $id = null, |
||
19 | ) { |
||
20 | 13 | } |
|
21 | |||
22 | 2 | public static function fromMessage(MessageInterface $message): self |
|
23 | { |
||
24 | 2 | return new self($message, $message->getMetadata()[self::MESSAGE_ID_KEY] ?? null); |
|
25 | } |
||
26 | |||
27 | public function setId(string|int|null $id): void |
||
28 | { |
||
29 | $this->id = $id; |
||
30 | } |
||
31 | |||
32 | 12 | public function getId(): string|int|null |
|
33 | { |
||
34 | 12 | return $this->id ?? $this->message->getMetadata()[self::MESSAGE_ID_KEY] ?? null; |
|
35 | } |
||
36 | |||
37 | 12 | private function getEnvelopeMetadata(): array |
|
0 ignored issues
–
show
|
|||
38 | { |
||
39 | 12 | return [self::MESSAGE_ID_KEY => $this->getId()]; |
|
40 | } |
||
41 | } |
||
42 |
This check looks for private methods that have been defined, but are not used inside the class.