Passed
Branch release/v3.0.0 (c409f3)
by Anatoly
05:44
created

HttpExceptionFactory::internalServerError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Http\Router\Exception;
15
16
use Fig\Http\Message\StatusCodeInterface;
17
use Sunrise\Http\Router\Dictionary\ErrorMessage;
18
use Throwable;
19
20
/**
21
 * @since 3.0.0
22
 */
23
final class HttpExceptionFactory
24
{
25 2
    public static function malformedUri(
26
        ?string $message = null,
27
        ?int $code = null,
28
        ?Throwable $previous = null,
29
    ): HttpException {
30 2
        return new HttpException(
31 2
            $message ?? ErrorMessage::MALFORMED_URI,
32 2
            $code ?? StatusCodeInterface::STATUS_BAD_REQUEST,
33 2
            $previous,
34 2
        );
35
    }
36
37 2
    public static function resourceNotFound(
38
        ?string $message = null,
39
        ?int $code = null,
40
        ?Throwable $previous = null,
41
    ): HttpException {
42 2
        return new HttpException(
43 2
            $message ?? ErrorMessage::RESOURCE_NOT_FOUND,
44 2
            $code ?? StatusCodeInterface::STATUS_NOT_FOUND,
45 2
            $previous,
46 2
        );
47
    }
48
49 2
    public static function methodNotAllowed(
50
        ?string $message = null,
51
        ?int $code = null,
52
        ?Throwable $previous = null,
53
    ): HttpException {
54 2
        return new HttpException(
55 2
            $message ?? ErrorMessage::METHOD_NOT_ALLOWED,
56 2
            $code ?? StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED,
57 2
            $previous,
58 2
        );
59
    }
60
61 8
    public static function invalidVariable(
62
        ?string $message = null,
63
        ?int $code = null,
64
        ?Throwable $previous = null,
65
    ): HttpException {
66 8
        return new HttpException(
67 8
            $message ?? ErrorMessage::INVALID_VARIABLE,
68 8
            $code ?? StatusCodeInterface::STATUS_BAD_REQUEST,
69 8
            $previous,
70 8
        );
71
    }
72
73 7
    public static function invalidQuery(
74
        ?string $message = null,
75
        ?int $code = null,
76
        ?Throwable $previous = null,
77
    ): HttpException {
78 7
        return new HttpException(
79 7
            $message ?? ErrorMessage::INVALID_QUERY,
80 7
            $code ?? StatusCodeInterface::STATUS_BAD_REQUEST,
81 7
            $previous,
82 7
        );
83
    }
84
85 2
    public static function missingHeader(
86
        ?string $message = null,
87
        ?int $code = null,
88
        ?Throwable $previous = null,
89
    ): HttpException {
90 2
        return new HttpException(
91 2
            $message ?? ErrorMessage::MISSING_HEADER,
92 2
            $code ?? StatusCodeInterface::STATUS_BAD_REQUEST,
93 2
            $previous,
94 2
        );
95
    }
96
97 8
    public static function invalidHeader(
98
        ?string $message = null,
99
        ?int $code = null,
100
        ?Throwable $previous = null,
101
    ): HttpException {
102 8
        return new HttpException(
103 8
            $message ?? ErrorMessage::INVALID_HEADER,
104 8
            $code ?? StatusCodeInterface::STATUS_BAD_REQUEST,
105 8
            $previous,
106 8
        );
107
    }
108
109 2
    public static function missingCookie(
110
        ?string $message = null,
111
        ?int $code = null,
112
        ?Throwable $previous = null,
113
    ): HttpException {
114 2
        return new HttpException(
115 2
            $message ?? ErrorMessage::MISSING_COOKIE,
116 2
            $code ?? StatusCodeInterface::STATUS_BAD_REQUEST,
117 2
            $previous,
118 2
        );
119
    }
120
121 8
    public static function invalidCookie(
122
        ?string $message = null,
123
        ?int $code = null,
124
        ?Throwable $previous = null,
125
    ): HttpException {
126 8
        return new HttpException(
127 8
            $message ?? ErrorMessage::INVALID_COOKIE,
128 8
            $code ?? StatusCodeInterface::STATUS_BAD_REQUEST,
129 8
            $previous,
130 8
        );
131
    }
132
133 11
    public static function invalidBody(
134
        ?string $message = null,
135
        ?int $code = null,
136
        ?Throwable $previous = null,
137
    ): HttpException {
138 11
        return new HttpException(
139 11
            $message ?? ErrorMessage::INVALID_BODY,
140 11
            $code ?? StatusCodeInterface::STATUS_BAD_REQUEST,
141 11
            $previous,
142 11
        );
143
    }
144
145 5
    public static function internalServerError(
146
        ?string $message = null,
147
        ?int $code = null,
148
        ?Throwable $previous = null,
149
    ): HttpException {
150 5
        return new HttpException(
151 5
            $message ?? ErrorMessage::INTERNAL_SERVER_ERROR,
152 5
            $code ?? StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR,
153 5
            $previous,
154 5
        );
155
    }
156
}
157