BadPayloadException::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 1
nop 4
crap 2
1
<?php
2
3
namespace Tarantool\JobQueue\Exception;
4
5
class BadPayloadException extends \RuntimeException
6
{
7
    private $payload;
8
9 1
    public function __construct($payload, $message = '', $code = 0, \Throwable $previous = null)
10
    {
11 1
        parent::__construct($message ?: 'Bad payload.', $code, $previous);
12
13 1
        $this->payload = $payload;
14 1
    }
15
16
    public function getPayload()
17
    {
18
        return $this->payload;
19
    }
20
21
    public static function unexpectedType($payload, string $expectedType, string $class): self
22
    {
23
        $message = sprintf('%s expects payload to be %s, %s given.',
24
            $class,
25
            $expectedType,
26
            is_object($payload) ? get_class($payload) : gettype($payload)
27
        );
28
29
        return new self($payload, $message);
30
    }
31
32 1
    public static function missingOrEmptyKeyValue($payload, string $key, string $type, string $class): self
33
    {
34 1
        $message = "$class requires payload to have a \"$key\" key with a non-empty $type value.";
35
36 1
        return new self($payload, $message);
37
    }
38
}
39