ErrorResponse   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 2
1
<?php
2
3
/**
4
 * Author: Nil Portugués Calderó <[email protected]>
5
 * Date: 7/27/15
6
 * Time: 11:52 PM.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace NilPortugues\Api\JSend\Http\Message;
12
13
use NilPortugues\Api\Http\Message\AbstractResponse;
14
15
/**
16
 * Class ErrorResponse.
17
 */
18
class ErrorResponse extends AbstractResponse
19
{
20
    /**
21
     * @param string $message
22
     * @param int    $code
23
     * @param null   $data
24
     */
25
    public function __construct($message, $code = 500, $data = null)
26
    {
27
        $body = json_encode(
28
            array_filter(
29
                [
30
                    'status' => 'error',
31
                    'code' => $code,
32
                    'message' => (string) $message,
33
                    'data' => '',
34
                ]
35
            )
36
        );
37
38
        if ($data) {
39
            $body = str_replace('"data": ""', substr(substr($data, 1), 0, -1), $body);
40
        }
41
42
        $this->response = parent::instance($body, 500, $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...
43
    }
44
}
45