Completed
Pull Request — master (#10)
by
unknown
02:57
created

RequestException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 4
A getRequestBody() 0 4 1
A getErrorCode() 0 4 1
1
<?php
2
3
namespace Akeneo\SalesForce\Exception;
4
5
class RequestException extends \Exception
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $errorCode;
11
12
    /**
13
     * @var string
14
     */
15
    private $requestBody;
16
17
    /**
18
     * @param string $message
19
     * @param string $requestBody
20
     */
21
    public function __construct($message, $requestBody)
22
    {
23
        $this->requestBody = $requestBody;
24
        $error             = json_decode($requestBody, true);
25
26
        //Errors generated during the auth stage are different to those generated during normal requests
27
        if (isset($error['error']) && isset($error['error_description'])) {
28
            $this->errorCode = $error['error'];
29
            parent::__construct($error['error_description']);
30
        } elseif (isset($error[0]['message'])) {
31
            $this->errorCode = $error[0]['errorCode'];
32
            parent::__construct($error[0]['message']);
33
        } else {
34
            $this->errorCode = $error['errorCode'];
35
            parent::__construct($error['message']);
36
        }
37
    }
38
39
    /**
40
     * @return mixed
41
     */
42
    public function getRequestBody()
43
    {
44
        return $this->requestBody;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getErrorCode()
51
    {
52
        return $this->errorCode;
53
    }
54
}
55