AbstractException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
c 0
b 0
f 0
dl 0
loc 27
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeaders() 0 3 1
A getStatusCode() 0 3 1
A __construct() 0 13 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Ctw\Http\HttpException;
5
6
use Ctw\Http\HttpStatus;
7
use RuntimeException;
8
use Throwable;
9
10
abstract class AbstractException extends RuntimeException implements HttpExceptionInterface
11
{
12
    protected int   $statusCode;
13
14 160
    public function __construct(
15
        string $message = '',
16
        Throwable $previous = null,
17
        protected array $headers = [],
18
        int $code = 0
19
    ) {
20 160
        if ('' === $message) {
21 80
            $statusCode = $this->getStatusCode();
22 80
            $entity     = (new HttpStatus($statusCode))->get();
23 80
            $message    = sprintf('%d %s', $entity->statusCode, $entity->name);
24
        }
25
26 160
        parent::__construct($message, $code, $previous);
27
    }
28
29 160
    public function getStatusCode(): int
30
    {
31 160
        return $this->statusCode;
32
    }
33
34 80
    public function getHeaders(): array
35
    {
36 80
        return $this->headers;
37
    }
38
}
39