HttpError   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
c 0
b 0
f 0
dl 0
loc 50
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
1
<?php
2
3
namespace Helix\Site;
4
5
use RuntimeException;
6
use Throwable;
7
8
/**
9
 * An HTTP error with a user friendly message.
10
 */
11
class HttpError extends RuntimeException
12
{
13
14
    const MESSAGES = [
15
        400 => 'Bad Request',
16
        401 => 'Unauthorized',
17
        402 => 'Payment Required',
18
        403 => 'Forbidden',
19
        404 => 'Not Found',
20
        405 => 'Method Not Allowed',
21
        406 => 'Not Acceptable',
22
        407 => 'Proxy Authentication Required',
23
        408 => 'Request Timeout',
24
        409 => 'Conflict',
25
        410 => 'Gone',
26
        411 => 'Length Required',
27
        412 => 'Precondition Failed',
28
        413 => 'Payload Too Large',
29
        414 => 'URI Too Long',
30
        415 => 'Unsupported Media Type',
31
        416 => 'Range Not Satisfiable',
32
        417 => 'Expectation Failed',
33
        418 => "I'm a teapot", // RFC 2324
34
        422 => 'Unprocessable Entity', // WebDAV; RFC 4918
35
        423 => 'Locked', // WebDAV; RFC 4918
36
        424 => 'Failed Dependency', // WebDAV; RFC 4918
37
        428 => 'Precondition Required', // RFC 6585
38
        429 => 'Too Many Requests', // RFC 6585
39
        431 => 'Request Header Fields Too Large', // RFC 6585
40
        451 => 'Unavailable For Legal Reasons', // Internet draft
41
        500 => 'Internal Server Error',
42
        501 => 'Not Implemented',
43
        502 => 'Bad Gateway',
44
        503 => 'Service Unavailable',
45
        504 => 'Gateway Timeout',
46
        506 => 'Variant Also Negotiates', // RFC 2295
47
        507 => 'Insufficient Storage', // WebDAV; RFC 4918
48
        508 => 'Loop Detected', // WebDAV; RFC 5842
49
        510 => 'Not Extended', // RFC 2774
50
    ];
51
52
    /**
53
     * @param int $code `4xx|5xx`
54
     * @param null|string $message Defaults to the standard description.
55
     * @param Throwable|null $previous
56
     */
57
    public function __construct(int $code, string $message = null, Throwable $previous = null)
58
    {
59
        $message = $message ?? self::MESSAGES[$code] ?? '';
60
        parent::__construct($message, $code, $previous);
61
    }
62
}
63