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

HttpError::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 3
crap 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