Test Failed
Push — develop ( e6fbfe...96413a )
by Jens
30:54
created

ErrorResponse   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 6
eloc 11
c 1
b 1
f 1
dl 0
loc 49
ccs 11
cts 11
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isError() 0 3 1
A __construct() 0 8 1
A getMessage() 0 7 3
A getException() 0 3 1
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Response;
7
8
use Commercetools\Core\Error\ErrorContainer;
9
use Commercetools\Core\Model\Common\Context;
10
use Commercetools\Core\Request\ClientRequestInterface;
11
use Psr\Http\Message\ResponseInterface;
12
13
class ErrorResponse extends AbstractApiResponse
14
{
15
    /**
16
     * @var \Exception
17
     */
18
    private $exception;
19
20
    /**
21
     * @var string
22
     */
23
    private $message;
24
25
    /**
26
     * ErrorResponse constructor.
27
     * @param ResponseInterface $response
28
     * @param ClientRequestInterface $request
29
     * @param \Exception $exception
30
     * @param Context $context
31
     */
32 16
    public function __construct(
33
        \Exception $exception,
34
        ClientRequestInterface $request,
35
        ResponseInterface $response,
36
        Context $context = null
37
    ) {
38 16
        parent::__construct($response, $request, $context);
39 16
        $this->exception = $exception;
40 16
    }
41
42 11
    public function isError()
43
    {
44 11
        return true;
45
    }
46
47 2
    public function getMessage()
48
    {
49 2
        if (is_null($this->message)) {
0 ignored issues
show
introduced by
The condition is_null($this->message) is always false.
Loading history...
50 2
            $message = $this->getResponseField('message', null);
51 2
            $this->message = !is_null($message) ? $message : $this->getResponse()->getReasonPhrase();
52
        }
53 2
        return $this->message;
54
    }
55
56
    /**
57
     * @return \Exception
58
     */
59
    public function getException()
60
    {
61
        return $this->exception;
62
    }
63
}
64