BadPayloadException   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 46.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 32
ccs 7
cts 15
cp 0.4667
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A missingOrEmptyKeyValue() 0 5 1
A unexpectedType() 0 9 2
A getPayload() 0 3 1
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