Completed
Push — master ( bcc5ea...52a3e2 )
by CloudyCity
01:11
created

ApiException::getApiFailures()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CloudyCity\UCMarketingSDK\Kernel\Exceptions;
4
5
use Psr\Http\Message\ResponseInterface;
6
7
/**
8
 * Class ApiException.
9
 */
10
class ApiException extends Exception
11
{
12
    /**
13
     * @var \Psr\Http\Message\ResponseInterface|null
14
     */
15
    public $response;
16
17
    /**
18
     * @var \Psr\Http\Message\ResponseInterface|\Doctrine\Common\Collections\ArrayCollection|array|object|string|null
19
     */
20
    public $formattedResponse;
21
22
    /**
23
     * HttpException constructor.
24
     *
25
     * @param string                                   $message
26
     * @param \Psr\Http\Message\ResponseInterface|null $response
27
     * @param mixed                                    $formattedResponse
28
     * @param int|null                                 $code
29
     */
30
    public function __construct($message, ResponseInterface $response = null, $formattedResponse = null, $code = null)
31
    {
32
        parent::__construct($message, $code);
33
34
        $this->response = $response;
35
        $this->formattedResponse = $formattedResponse;
36
37
        if ($response) {
38
            $response->getBody()->rewind();
39
        }
40
    }
41
42
    /**
43
     * @return array
44
     */
45
    public function getApiFailures()
46
    {
47
        if (isset($this->formattedResponse['header']['failures'])) {
48
            return $this->formattedResponse['header']['failures'];
49
        } else {
50
            return [];
51
        }
52
    }
53
54
    /**
55
     * @return string|null
56
     */
57 View Code Duplication
    public function getApiMessage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        if (isset($this->formattedResponse['header']['failures'][0]['message'])) {
60
            return $this->formattedResponse['header']['failures'][0]['message'];
61
        } else {
62
            return null;
63
        }
64
    }
65
66
    /**
67
     * @return int|null
68
     */
69 View Code Duplication
    public function getApiCode()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        if (isset($this->formattedResponse['header']['failures'][0]['code'])) {
72
            return $this->formattedResponse['header']['failures'][0]['code'];
73
        } else {
74
            return null;
75
        }
76
    }
77
}
78