Completed
Pull Request — develop (#189)
by Jens
11:13
created

ErrorResponse::getMessage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * @author @jayS-de <[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
    private $message;
21
    private $statusCode;
0 ignored issues
show
Unused Code introduced by
The property $statusCode is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
22
23
    /**
24
     * ErrorResponse constructor.
25
     * @param ResponseInterface $response
26
     * @param ClientRequestInterface $request
27
     * @param \Exception $exception
28
     * @param Context $context
29
     */
30 26
    public function __construct(
31
        \Exception $exception,
32
        ClientRequestInterface $request,
33
        ResponseInterface $response = null,
34
        Context $context = null
35
    ) {
36 26
        parent::__construct($response, $request, $context);
0 ignored issues
show
Bug introduced by
It seems like $response defined by parameter $response on line 33 can be null; however, Commercetools\Core\Respo...Response::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
37 26
        $this->exception = $exception;
38 26
    }
39
40 22
    public function isError()
41
    {
42 22
        return true;
43
    }
44
45
    public function getMessage()
46
    {
47
        if (is_null($this->message)) {
48
            $this->message = $this->getResponseField('message');
49
        }
50
        return $this->message;
51
    }
52
}
53