NoKeyInPayloadException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getName() 0 3 1
A getSolution() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Queue\AMQP\Exception;
6
7
use InvalidArgumentException;
8
use Throwable;
9
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
10
use Yiisoft\Queue\AMQP\MessageSerializerInterface;
11
12
class NoKeyInPayloadException extends InvalidArgumentException implements FriendlyExceptionInterface
13
{
14
    public function __construct(
15
        protected string $expectedKey,
16
        protected array $payload,
17
        int $code = 0,
18
        Throwable $previous = null
19
    ) {
20
        parent::__construct(
21
            "No expected key '$expectedKey' in payload. Payload's keys list: " .
22
            implode(', ', array_keys($payload)) .
23
            '.',
24
            $code,
25
            $previous
26
        );
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getName(): string
33
    {
34
        return 'No key "' . $this->expectedKey . '" in payload';
35
    }
36
37
    /**
38
     * @return string
39
     *
40
     * @infection-ignore-all
41
     */
42
    public function getSolution(): ?string
43
    {
44
        return sprintf(
45
            "We have successfully unserialized a message, but there was no expected key \"%s\".
46
        There are the following keys in the message: %s.
47
        You might want to change message's structure, or make your own implementation of %s,
48
        which won't rely on this key in the message.",
49
            $this->expectedKey,
50
            implode(', ', array_keys($this->payload)),
51
            MessageSerializerInterface::class
52
        );
53
    }
54
}
55