Passed
Pull Request — master (#190)
by Dmitriy
04:22 queued 01:36
created

HandlerEnvelope   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 33
ccs 0
cts 9
cp 0
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getEnvelopeMetadata() 0 4 1
A getHandler() 0 4 2
A setHandler() 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 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
    /**
23
     * @psalm-param class-string<MessageHandlerInterface> $handlerClass
24
     */
25
    public function setHandler(string $handlerClass): void
26
    {
27
        $this->handlerClass = $handlerClass;
28
    }
29
30
    /**
31
     * @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...
32
     */
33
    public function getHandler(): string
34
    {
35
        /** @psalm-suppress LessSpecificReturnStatement  */
36
        return $this->handlerClass ?: $this->message->getMetadata()[self::HANDLER_CLASS_KEY];
37
    }
38
39
    public function getEnvelopeMetadata(): array
40
    {
41
        return [
42
            self::HANDLER_CLASS_KEY => $this->handlerClass,
43
        ];
44
    }
45
}
46