Completed
Pull Request — master (#18)
by
unknown
02:15
created

RequestException   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 95.45%

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 21
cts 22
cp 0.9545
rs 10
c 0
b 0
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
C __construct() 0 23 7
A getResponseCode() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: gorkalaucirica
5
 * Date: 09/07/14
6
 * Time: 12:33
7
 */
8
9
namespace SolutionDrive\HipchatAPIv2Client\Exception;
10
11
12
class RequestException extends \Exception implements RequestExceptionInterface
13
{
14
    protected $responseCode;
15
16
    protected $message;
17
18
    protected $type;
19
20
    /**
21
     * Request exception constructor
22
     *
23
     * @param string $response json_decoded array with the error response given by the server
24
     */
25 4
    public function __construct($response)
26
    {
27 4
        $message = '';
28 4
        $code = null;
29 4
        $type = null;
30 4
        if (is_string($response)) {
0 ignored issues
show
introduced by
The condition is_string($response) can never be false.
Loading history...
31
            $message = $response;
32 4
        } elseif (is_array($response)) {
33 4
            $error = isset($response['error']) ? $response['error'] : '';
34 4
            if (isset($error['code'])) {
35 4
                $code = $error['code'];
36
            }
37 4
            if (isset($error['message'])) {
38 4
                $message = $error['message'];
39
            }
40 4
            if (isset($error['type'])) {
41 4
                $type = $error['type'];
42
            }
43
        }
44
45 4
        $this->responseCode = $code;
46 4
        $this->type = $type;
47 4
        parent::__construct($message, $code);
48 4
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53 1
    public function getResponseCode()
54
    {
55 1
        return $this->responseCode;
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61 1
    public function getType()
62
    {
63 1
        return $this->type;
64
    }
65
}
66