AbstractErrorResponse   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getDefaultError() 0 4 1
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 11/21/15
5
 * Time: 1:21 PM.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace NilPortugues\Api\JsonApi\Http\Response;
11
12
use NilPortugues\Api\JsonApi\Server\Errors\ErrorBag;
13
14
/**
15
 * Class AbstractErrorResponse.
16
 */
17
abstract class AbstractErrorResponse extends AbstractResponse
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $errorCode;
23
24
    /**
25
     * ErrorBag as defined in http://jsonapi.org/format/#error-objects;.
26
     *
27
     * @link     http://jsonapi.org/format/#error-objects
28
     *
29
     * @param ErrorBag $errors
30
     */
31
    public function __construct(ErrorBag $errors = null)
32
    {
33
        $body = $this->getDefaultError();
34
35
        if (null !== $errors) {
36
            $errors->setHttpCode($this->httpCode);
37
            $body = json_encode($errors, JSON_UNESCAPED_SLASHES);
38
        }
39
40
        $this->response = parent::instance($body, $this->httpCode, $this->headers);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (instance() instead of __construct()). Are you sure this is correct? If so, you might want to change this to $this->instance().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    protected function getDefaultError()
47
    {
48
        return json_encode(['errors' => [['status' => $this->httpCode, 'code' => $this->errorCode]]]);
49
    }
50
}
51