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.

ServiceExceptionFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A exception() 0 19 5
A make() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Honeybadger\Exceptions;
4
5
use Exception;
6
use Psr\Http\Message\ResponseInterface;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class ServiceExceptionFactory
10
{
11
    /**
12
     * @var \Psr\Http\Message\ResponseInterface
13
     */
14
    protected $response;
15
16
    /**
17
     * @param  \Psr\Http\Message\ResponseInterface  $response
18
     */
19
    public function __construct(ResponseInterface $response)
20
    {
21
        $this->response = $response;
22
    }
23
24
    public function make(): Exception
25
    {
26
        return $this->exception();
27
    }
28
29
    /**
30
     * @return void
31
     *
32
     * @throws \Honeybadger\Exceptions\ServiceException
33
     */
34
    private function exception(): void
35
    {
36
        if ($this->response->getStatusCode() === Response::HTTP_FORBIDDEN) {
37
            throw ServiceException::invalidApiKey();
38
        }
39
40
        if ($this->response->getStatusCode() === Response::HTTP_UNPROCESSABLE_ENTITY) {
41
            throw ServiceException::invalidPayload();
42
        }
43
44
        if ($this->response->getStatusCode() === Response::HTTP_TOO_MANY_REQUESTS) {
45
            throw ServiceException::rateLimit();
46
        }
47
48
        if ($this->response->getStatusCode() === Response::HTTP_INTERNAL_SERVER_ERROR) {
49
            throw ServiceException::serverError();
50
        }
51
52
        throw ServiceException::generic();
53
    }
54
}
55