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.

transformResponseToException()   B
last analyzed

Complexity

Conditions 11
Paths 8

Size

Total Lines 33
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 15
c 1
b 0
f 0
nc 8
nop 2
dl 0
loc 33
rs 7.3166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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