Passed
Push — main ( d3d78c...a401b7 )
by Thomas
03:23
created

HttpError   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 33
ccs 12
cts 12
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A withPayload() 0 6 1
A setPayload() 0 3 1
A __construct() 0 6 1
A getTitle() 0 3 1
A getPayload() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Chuck\Exception;
6
7
use Exception;
8
use Throwable;
9
10
/**
11
 * @psalm-api
12
 *
13
 * @psalm-consistent-constructor
14
 */
15
abstract class HttpError extends Exception implements ChuckException
16
{
17
    protected mixed $payload = null;
18
19 14
    public function __construct(
20
        string $message = '',
21
        int $code = 0,
22
        ?Throwable $previous = null
23
    ) {
24 14
        parent::__construct($message, $code, $previous);
25
    }
26
27 1
    public static function withPayload(mixed $payload): static
28
    {
29 1
        $exception = new static();
30 1
        $exception->setPayload($payload);
31
32 1
        return $exception;
33
    }
34
35 4
    public function getTitle(): string
36
    {
37 4
        return (string)$this->getCode() . ' ' . $this->getMessage();
38
    }
39
40 1
    public function setPayload(mixed $payload): void
41
    {
42 1
        $this->payload = $payload;
43
    }
44
45 4
    public function getPayload(): mixed
46
    {
47 4
        return $this->payload;
48
    }
49
}
50