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

ErrorResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 4
c 3
b 0
f 2
lcom 1
cbo 1
dl 0
loc 40
ccs 6
cts 6
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A isError() 0 4 1
A getMessage() 0 7 2
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