Completed
Push — master ( cc8ae8...627a43 )
by Zbigniew
02:21
created

ApiException   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 10

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 0
cbo 10
dl 0
loc 56
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
C create() 0 35 12
1
<?php
2
/**
3
 * This file is part of the WrikePhpSdk package.
4
 *
5
 * (c) Zbigniew Ślązak
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Zibios\WrikePhpSdk\Exceptions\Api;
12
13
use Exception;
14
use GuzzleHttp\Exception\ClientException;
15
use GuzzleHttp\Exception\ServerException;
16
17
/**
18
 * General Wrike Api Exception
19
 *
20
 * Thrown when the Wrike API returns an HTTP error that isn't handled by other dedicated exceptions.
21
 */
22
class ApiException extends Exception
23
{
24
    /** @var  \Exception */
25
    protected $responseException;
26
27
    /**
28
     * ApiException constructor.
29
     *
30
     * @param Exception $e
31
     */
32 28
    public function __construct(\Exception $e)
33
    {
34 28
        parent::__construct($e->getMessage(), $e->getCode(), $e);
35 28
    }
36
37
    /**
38
     * @param \Exception $e
39
     *
40
     * @return ApiException
41
     */
42 18
    public static function create(\Exception $e)
43
    {
44 18
        if ($e instanceof ClientException === false && $e instanceof ServerException === false) {
45 1
            return new ApiException($e);
46
        }
47
        /** @var ClientException $e */
48 17
        $errorResponse = $e->getResponse();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
49 17
        $bodyString = (string) $errorResponse->getBody();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
50 17
        $body = json_decode($bodyString, true);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
51 17
        $errorStatusCode = $errorResponse->getStatusCode();
52 17
        $errorName = $body['error'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
53
54 17
        switch ($errorStatusCode . $errorName) {
55 17
            case (AccessForbiddenException::STATUS_CODE . AccessForbiddenException::STATUS_NAME):
56 1
                return new AccessForbiddenException($e);
57 16
            case (InvalidParameterException::STATUS_CODE . InvalidParameterException::STATUS_NAME):
58 1
                return new InvalidParameterException($e);
59 15
            case (InvalidRequestException::STATUS_CODE . InvalidRequestException::STATUS_NAME):
60 1
                return new InvalidRequestException($e);
61 14
            case (MethodNotFoundException::STATUS_CODE . MethodNotFoundException::STATUS_NAME):
62 1
                return new MethodNotFoundException($e);
63 13
            case (NotAllowedException::STATUS_CODE . NotAllowedException::STATUS_NAME):
64 1
                return new NotAllowedException($e);
65 12
            case (NotAuthorizedException::STATUS_CODE . NotAuthorizedException::STATUS_NAME):
66 1
                return new NotAuthorizedException($e);
67 11
            case (ParameterRequiredException::STATUS_CODE . ParameterRequiredException::STATUS_NAME):
68 1
                return new ParameterRequiredException($e);
69 10
            case (ResourceNotFoundException::STATUS_CODE . ResourceNotFoundException::STATUS_NAME):
70 1
                return new ResourceNotFoundException($e);
71 9
            case (ServerErrorException::STATUS_CODE . ServerErrorException::STATUS_NAME):
72 1
                return new ServerErrorException($e);
73 8
            default:
74 8
                return new ApiException($e);
75 8
        }
76
    }
77
}
78