Passed
Push — master ( 5339df...fb5d3c )
by Alexander
03:17
created

EnvelopeTrait::fromMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Queue\Message;
6
7
trait EnvelopeTrait
8
{
9
    private MessageInterface $message;
10
11 4
    public function getMessage(): MessageInterface
12
    {
13 4
        return $this->message;
14
    }
15
16
    public function withMessage(MessageInterface $message): self
17
    {
18
        $instance = clone $this;
19
        $instance->message = $message;
20
21
        return $instance;
22
    }
23
24 8
    public function getHandlerName(): string
25
    {
26 8
        return $this->message->getHandlerName();
27
    }
28
29 4
    public function getData(): mixed
30
    {
31 4
        return $this->message->getData();
32
    }
33
34 2
    public static function fromMessage(MessageInterface $message): self
35
    {
36 2
        return new static($message);
0 ignored issues
show
Unused Code introduced by
The call to Yiisoft\Queue\Message\EnvelopeTrait::__construct() has too many arguments starting with $message. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        return /** @scrutinizer ignore-call */ new static($message);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
37
    }
38
39 12
    public function getMetadata(): array
40
    {
41 12
        return array_merge(
42 12
            $this->message->getMetadata(),
43 12
            [
44 12
                self::ENVELOPE_STACK_KEY => array_merge(
0 ignored issues
show
Bug introduced by
The constant Yiisoft\Queue\Message\En...ait::ENVELOPE_STACK_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
45 12
                    $this->message->getMetadata()[self::ENVELOPE_STACK_KEY] ?? [],
46 12
                    [self::class],
47 12
                ),
48 12
            ],
49 12
            $this->getEnvelopeMetadata(),
50 12
        );
51
    }
52
53
    public function getEnvelopeMetadata(): array
54
    {
55
        return [];
56
    }
57
}
58