GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ExceptionFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Tools\Psr7\HttpStatusExceptions;
4
5
use Exception as CoreException;
6
use Psr\Http\Message\ResponseInterface;
7
8
final class ExceptionFactory
9
{
10
    const STATUS_CODE_EXCEPTION_MAP = [
11
        /**
12
         * 1xx codes.
13
         */
14
        100 => ContinueException::class,
15
        101 => SwitchingProtocolsException::class,
16
        102 => ProcessingException::class,
17
18
        /**
19
         * 2xx codes.
20
         */
21
        200 => OKException::class,
22
        201 => CreatedException::class,
23
        202 => AcceptedException::class,
24
        203 => NonAuthoritativeInformationException::class,
25
        204 => NoContentException::class,
26
        205 => ResetContentException::class,
27
        206 => PartialContentException::class,
28
        207 => MultiStatusException::class,
29
        208 => AlreadyReportedException::class,
30
        226 => IMUsedException::class,
31
32
        /**
33
         * 3xx codes.
34
         */
35
        300 => MultiChoicesException::class,
36
        301 => MovedPermanentlyException::class,
37
        302 => FoundException::class,
38
        303 => SeeOtherException::class,
39
        304 => NotModifiedException::class,
40
        305 => UseProxyException::class,
41
        306 => SwitchProxyException::class,
42
        307 => TemporaryRedirectException::class,
43
        308 => PermanentRedirectException::class,
44
45
        /**
46
         * 4xx codes.
47
         */
48
        400 => BadRequestException::class,
49
        401 => UnauthorizedException::class,
50
        402 => PaymentRequiredException::class,
51
        403 => ForbiddenException::class,
52
        404 => NotFoundException::class,
53
        405 => MethodNotAllowedException::class,
54
        406 => NotAcceptableException::class,
55
        407 => ProxyAuthenticationRequiredException::class,
56
        408 => RequestTimeoutException::class,
57
        409 => ConflictException::class,
58
        410 => GoneException::class,
59
        411 => LengthRequiredException::class,
60
        412 => PreconditionFailedException::class,
61
        413 => PayloadTooLargeException::class,
62
        414 => URITooLongException::class,
63
        415 => UnsupportedMediaTypeException::class,
64
        416 => RangeNotSatisfiableException::class,
65
        417 => ExpectationFailedException::class,
66
        418 => ImATeapotException::class,
67
        421 => MisdirectedRequestException::class,
68
        422 => UnprocessableEntityException::class,
69
        423 => LockedException::class,
70
        424 => FailedDependencyException::class,
71
        426 => UpgradeRequiredException::class,
72
        428 => PreconditionRequiredException::class,
73
        429 => TooManyRequestsException::class,
74
        431 => RequestHeaderFieldsTooLargeException::class,
75
        451 => UnavailableForLegalReasonsException::class,
76
77
        /**
78
         * 5xx codes.
79
         */
80
        500 => InternalServerErrorException::class,
81
        501 => NotImplementedException::class,
82
        502 => BadGatewayException::class,
83
        503 => ServiceUnavailableException::class,
84
        504 => GatewayTimeoutException::class,
85
        505 => HTTPVersionNotSupportedException::class,
86
        506 => VariantAlsoNegotiatesException::class,
87
        507 => InsufficientStorageException::class,
88
        508 => LoopDetectedException::class,
89
        510 => NotExtendedException::class,
90
        511 => NetworkAuthenticationRequiredException::class,
91
92
        /**
93
         * IIS (Unofficial).
94
         *
95
         * Excluding the 451 as it conflicts with the official 451 code.
96
         */
97
        440 => Unofficial\IIS\LoginTimeoutException::class,
98
        449 => Unofficial\IIS\RetryWithException::class,
99
100
        /**
101
         * Cloudflare (Unofficial).
102
         */
103
        520 => Unofficial\Cloudflare\UnknownErrorException::class,
104
        521 => Unofficial\Cloudflare\WebServerIsDownException::class,
105
        522 => Unofficial\Cloudflare\ConnectionTimedOutException::class,
106
        523 => Unofficial\Cloudflare\OriginIsUnreachableException::class,
107
        524 => Unofficial\Cloudflare\ATimeoutOccurredException::class,
108
        525 => Unofficial\Cloudflare\SSLHandshakeFailedException::class,
109
        526 => Unofficial\Cloudflare\InvalidSSLCertificateException::class,
110
        527 => Unofficial\Cloudflare\RailgunErrorException::class,
111
    ];
112
113 71
    public static function create(ResponseInterface $response, CoreException $previousException)
114
    {
115 71
        $exception = static::STATUS_CODE_EXCEPTION_MAP[$response->getStatusCode()];
116
117 71
        return $exception::create($response, $previousException);
118
    }
119
}
120