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.

Factory::createFromResponse()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 12
c 2
b 1
f 1
dl 0
loc 15
rs 9.5555
cc 5
nc 5
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Monobank\Exception;
6
7
use Psr\Http\Message\ResponseInterface;
8
9
final class Factory
10
{
11
    private const INVALID_ACCOUNT = 'invalid account';
12
13
    private const UNKNOWN_TOKEN = 'Unknown \'X-Token\'';
14
15
    private const TOO_MANY_REQUESTS = 'Too many requests';
16
17
    private const INTERNAL_ERROR = 'internal error';
18
19
    public static function createFromResponse(ResponseInterface $response)
20
    {
21
        $errorDescription = json_decode($response->getBody()->getContents(), true)['errorDescription'] ?? 'Unknown error';
22
23
        switch ($errorDescription) {
24
            case self::INVALID_ACCOUNT:
25
                return new InvalidAccountException($errorDescription);
26
            case self::UNKNOWN_TOKEN:
27
                return new UnknownTokenException($errorDescription);
28
            case self::TOO_MANY_REQUESTS:
29
                return new TooManyRequestsException($errorDescription);
30
            case self::INTERNAL_ERROR:
31
                return new InternalErrorException($errorDescription);
32
            default:
33
                return new MonobankException($errorDescription);
34
        }
35
    }
36
}
37