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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 5
eloc 17
c 2
b 1
f 1
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createFromResponse() 0 15 5
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