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.

HttpExceptionHandler   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 11

1 Method

Rating   Name   Duplication   Size   Complexity  
B transformResponseToException() 0 33 11
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaignApi\Client;
7
8
use CommerceLeague\ActiveCampaignApi\Exception\BadRequestHttpException;
9
use CommerceLeague\ActiveCampaignApi\Exception\ClientErrorHttpException;
10
use CommerceLeague\ActiveCampaignApi\Exception\NotFoundHttpException;
11
use CommerceLeague\ActiveCampaignApi\Exception\RedirectionHttpException;
12
use CommerceLeague\ActiveCampaignApi\Exception\ServerErrorHttpException;
13
use CommerceLeague\ActiveCampaignApi\Exception\UnauthorizedHttpException;
14
use CommerceLeague\ActiveCampaignApi\Exception\UnprocessableEntityHttpException;
15
use Psr\Http\Message\RequestInterface;
16
use Psr\Http\Message\ResponseInterface;
17
18
/**
19
 * Class HttpExceptionHandler
20
 */
21
class HttpExceptionHandler
22
{
23
    /**
24
     * @param RequestInterface $request
25
     * @param ResponseInterface $response
26
     * @return ResponseInterface
27
     */
28
    public function transformResponseToException(
29
        RequestInterface $request,
30
        ResponseInterface $response
31
    ): ResponseInterface {
32
        if ($response->getStatusCode() >= 300 && $response->getStatusCode() < 400) {
33
            throw new RedirectionHttpException($response->getReasonPhrase(), $request, $response);
34
        }
35
36
        if ($response->getStatusCode() === 400) {
37
            throw new BadRequestHttpException($response->getReasonPhrase(), $request, $response);
38
        }
39
40
        if ($response->getStatusCode() === 401) {
41
            throw new UnauthorizedHttpException($response->getReasonPhrase(), $request, $response);
42
        }
43
44
        if ($response->getStatusCode() === 404) {
45
            throw new NotFoundHttpException($response->getReasonPhrase(), $request, $response);
46
        }
47
48
        if ($response->getStatusCode() === 422) {
49
            throw new UnprocessableEntityHttpException($response->getReasonPhrase(), $request, $response);
50
        }
51
52
        if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 500) {
53
            throw new ClientErrorHttpException($response->getReasonPhrase(), $request, $response);
54
        }
55
56
        if ($response->getStatusCode() >= 500 && $response->getStatusCode() < 600) {
57
            throw new ServerErrorHttpException($response->getReasonPhrase(), $request, $response);
58
        }
59
60
        return $response;
61
    }
62
}
63