Completed
Push — master ( 8ca3f0...97b52a )
by Alexander
01:51
created

Response   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 68
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fileEndingFromType() 0 8 3
1
<?php
2
3
namespace alkemann\h2l;
4
5
/**
6
 * Abstract class Response
7
 *
8
 * @package alkemann\h2l
9
 */
10
abstract class Response extends Message
11
{
12
    public static $code_to_message = [
13
        // Informational 1xx
14
        100 => 'Continue',
15
        101 => 'Switching Protocols',
16
        // Successful 2xx
17
        200 => 'OK',
18
        201 => 'Created',
19
        202 => 'Accepted',
20
        203 => 'Non-Authoritative Information',
21
        204 => 'No Content',
22
        205 => 'Reset Content',
23
        206 => 'Partial Content',
24
        // Redirection 3xx
25
        300 => 'Multiple Choices',
26
        301 => 'Moved Permanently',
27
        302 => 'Found',
28
        303 => 'See Other',
29
        304 => 'Not Modified',
30
        305 => 'Use Proxy',
31
        307 => 'Temporary Redirect',
32
        // Client Error 4xx
33
        400 => 'Bad Request',
34
        401 => 'Unauthorized',
35
        402 => 'Payment Required',
36
        403 => 'Forbidden',
37
        404 => 'Not Found',
38
        405 => 'Method Not Allowed',
39
        406 => 'Not Acceptable',
40
        407 => 'Proxy Authentication Required',
41
        408 => 'Request Timeout',
42
        409 => 'Conflict',
43
        410 => 'Gone',
44
        411 => 'Length Required',
45
        412 => 'Precondition Failed',
46
        413 => 'Request Entity Too Large',
47
        414 => 'Request-URI Too Long',
48
        415 => 'Unsupported Media Type',
49
        416 => 'Requested Range Not Satisfiable',
50
        417 => 'Expectation Failed',
51
        // Server Error 5xx
52
        500 => 'Internal Server Error',
53
        501 => 'Not Implemented',
54
        502 => 'Bad Gateway',
55
        503 => 'Service Unavailable',
56
        504 => 'Gateway Timeout',
57
        505 => 'HTTP Version Not Supported',
58
    ];
59
60
    protected static $contentTypes = [
61
        'text/html' => 'html',
62
        'application/json' => 'json',
63
        'application/xml' => 'xml',
64
        'text/xml' => 'xml',
65
    ];
66
67
    public function fileEndingFromType(string $type): string
68
    {
69
        foreach (static::$contentTypes as $type_key => $ending) {
70
            if ($type === $type_key) {
71
                return $ending;
72
            }
73
        }
74
        return 'html';
75
    }
76
77
    abstract public function render(): string;
78
}
79