Passed
Pull Request — master (#190)
by Alexander
05:09 queued 02:32
created

HandlerEnvelope   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandler() 0 3 1
A setHandler() 0 3 1
A getMetadata() 0 4 1
A __construct() 0 4 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 13
    public function __construct(
17
        private MessageInterface $message,
18
        private string $handlerClass,
19
    ) {
20 13
    }
21
22
    public function setHandler(string $handlerClass): void
23
    {
24
        $this->handlerClass = $handlerClass;
25
    }
26
27 13
    public function getHandler(): string
28
    {
29 13
        return $this->handlerClass ?? $this->message->getMetadata()[self::HANDLER_CLASS_KEY];
30
    }
31
32 13
    public function getMetadata(): array
33
    {
34 13
        return array_merge($this->message->getMetadata(), [
35 13
            self::HANDLER_CLASS_KEY => $this->getHandler(),
36 13
        ]);
37
    }
38
}
39