Completed
Push — master ( 2b4de6...20220d )
by Matthew
02:17
created

ApiException   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 11

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
c 2
b 0
f 0
lcom 0
cbo 11
dl 0
loc 67
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
C create() 0 24 10
A getRequestException() 0 4 1
A __construct() 0 5 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Matt
5
 */
6
7
namespace Freshdesk\Exceptions;
8
9
use Exception;
10
use GuzzleHttp\Exception\RequestException;
11
12
/**
13
 * General Exception
14
 *
15
 * Thrown when the Freshdesk API returns an HTTP error code that isn't handled by other exceptions
16
 *
17
 * @package Exceptions
18
 * @author Matthew Clarkson <[email protected]>
19
 */
20
class ApiException extends Exception
21
{
22
23
    /**
24
     * @internal
25
     * @param RequestException $e
26
     * @return AccessDeniedException|ApiException|AuthenticationException|ConflictingStateException|
27
     * MethodNotAllowedException|NotFoundException|RateLimitExceededException|UnsupportedAcceptHeaderException|
28
     * UnsupportedContentTypeException|ValidationException
29
     */
30
    static function create(RequestException $e) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
31
        switch ($e->getResponse()->getStatusCode()) {
32
            case 400:
33
                return new ValidationException($e);
34
            case 401:
35
                return new AuthenticationException($e);
36
            case 403:
37
                return new AccessDeniedException($e);
38
            case 404:
39
                return new NotFoundException($e);
40
            case 405:
41
                return new MethodNotAllowedException($e);
42
            case 406:
43
                return new UnsupportedAcceptHeaderException($e);
44
            case 409:
45
                return new ConflictingStateException($e);
46
            case 415:
47
                return new UnsupportedContentTypeException($e);
48
            case 429:
49
                return new RateLimitExceededException($e);
50
            default:
51
                return new ApiException($e);
52
        }
53
    }
54
55
    /**
56
     * @var RequestException
57
     * @internal
58
     */
59
    private $exception;
60
61
    /**
62
     * Returns the Request Exception
63
     *
64
     * A Guzzle Request Exception is returned
65
     *
66
     * @return RequestException
67
     */
68
    public function getRequestException()
69
    {
70
        return $this->exception;
71
    }
72
73
    /**
74
     * Exception constructor
75
     *
76
     * Constructs a new exception.
77
     *
78
     * @param RequestException $e
79
     * @internal
80
     */
81
    public function __construct(RequestException $e)
82
    {
83
        $this->exception = $e;
84
        parent::__construct();
85
    }
86
}
87