Passed
Pull Request — master (#190)
by Alexander
12:54
created

HandlerEnvelope::setHandler()   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
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
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 HandlerEnvelope implements EnvelopeInterface
11
{
12
    use EnvelopeTrait;
13
14
    public const HANDLER_CLASS_KEY = 'handler_class';
15
16
    public function __construct(
17
        private MessageInterface $message,
18
        private string $handlerClass = '',
19
    ) {
20
    }
21
22
    public function setHandler(string $handlerClass): void
23
    {
24
        $this->handlerClass = $handlerClass;
25
    }
26
27
    /**
28
     * @return class-string<MessageHandlerInterface>
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<MessageHandlerInterface> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<MessageHandlerInterface>.
Loading history...
29
     */
30
    public function getHandler(): string
31
    {
32
        return $this->handlerClass ?: $this->message->getMetadata()[self::HANDLER_CLASS_KEY];
33
    }
34
35
    public function getEnvelopeMetadata(): array
36
    {
37
        return [
38
            self::HANDLER_CLASS_KEY => $this->handlerClass,
39
        ];
40
    }
41
}
42