HttpException   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 52
ccs 13
cts 13
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 3 2
A __construct() 0 11 3
A getReasonPhrase() 0 3 1
A getStatusCode() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HttpSoft\Basis\Exception;
6
7
use Exception;
8
use HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface;
9
use Throwable;
10
11
class HttpException extends Exception
12
{
13
    /**
14
     * @var int
15
     */
16
    private int $statusCode;
17
18
    /**
19
     * @var string
20
     */
21
    private string $reasonPhrase;
22
23
    /**
24
     * @param int $statusCode
25
     * @param string|null $reasonPhrase
26
     * @param Throwable|null $previous
27
     */
28 39
    public function __construct(int $statusCode, ?string $reasonPhrase = null, ?Throwable $previous = null)
29
    {
30 39
        $reasonPhrase ??= '';
31
32 39
        if ($reasonPhrase === '' && isset(ErrorResponseGeneratorInterface::ERROR_PHRASES[$statusCode])) {
33 28
            $reasonPhrase = ErrorResponseGeneratorInterface::ERROR_PHRASES[$statusCode];
34
        }
35
36 39
        $this->statusCode = $statusCode;
37 39
        $this->reasonPhrase = $reasonPhrase;
38 39
        parent::__construct($reasonPhrase, $statusCode, $previous);
39
    }
40
41
    /**
42
     * @return int
43
     */
44 35
    public function getStatusCode(): int
45
    {
46 35
        return $this->statusCode;
47
    }
48
49
    /**
50
     * @return string
51
     */
52 35
    public function getReasonPhrase(): string
53
    {
54 35
        return $this->reasonPhrase;
55
    }
56
57
    /**
58
     * @return string
59
     */
60 26
    public function getTitle(): string
61
    {
62 26
        return $this->statusCode . ($this->reasonPhrase ? ' ' . $this->reasonPhrase : '');
63
    }
64
}
65