ErrorResponse   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 73
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A withCode() 0 6 1
A hasMessage() 0 4 1
A hasCode() 0 4 1
A withMessage() 0 6 1
A toArray() 0 14 3
1
<?php
2
3
namespace RichToms\LaravelJsend\Responses;
4
5
class ErrorResponse extends Response
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $statusText = 'error';
11
12
    /**
13
     * @var int|null
14
     */
15
    protected $code = null;
16
17
    /**
18
     * @var string|null
19
     */
20
    protected $message = null;
21
22
    /**
23
     * @param  int  $code
24
     * @return $this
25
     */
26
    public function withCode($code)
27
    {
28
        $this->code = $code;
29
30
        return $this;
31
    }
32
33
    /**
34
     * @return bool
35
     */
36
    public function hasMessage()
37
    {
38
        return ! is_null($this->message);
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public function hasCode()
45
    {
46
        return ! is_null($this->code);
47
    }
48
49
    /**
50
     * @param  string  $message
51
     * @return $this
52
     */
53
    public function withMessage($message)
54
    {
55
        $this->message = $message;
56
57
        return $this;
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function toArray()
64
    {
65
        $response = parent::toArray();
66
67
        if ($this->hasMessage()) {
68
            $response['message'] = $this->message;
69
        }
70
71
        if ($this->hasCode()) {
72
            $response['code'] = $this->code;
73
        }
74
75
        return $response;
76
    }
77
}
78