Completed
Pull Request — master (#5)
by Samuel
03:56 queued 01:56
created

AbstractResponse::setStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMartins\Exceptions\Response;
4
5
use Illuminate\Http\JsonResponse;
6
7
abstract class AbstractResponse
8
{
9
    /**
10
     * The HTTP status code.
11
     *
12
     * @var int
13
     */
14
    protected $status;
15
16
    /**
17
     * The errors on response.
18
     *
19
     * @var \SMartins\Exceptions\Response\ErrorHandledCollectionInterface
20
     */
21
    protected $errors;
22
23
    /**
24
     * Create new Response response passing the errors.
25
     *
26
     * @param \SMartins\Exceptions\Response\ErrorHandledCollectionInterface $errors
27
     */
28
    public function __construct(ErrorHandledCollectionInterface $errors)
29
    {
30
        $this->errors = $errors;
31
32
        $this->setStatus((int) $this->errors->getStatusCode());
33
    }
34
35
    /**
36
     * Get the HTTP status code.
37
     *
38
     * @return  int
39
     */
40
    public function getStatus()
41
    {
42
        return $this->status;
43
    }
44
45
    /**
46
     * Set the HTTP status code.
47
     *
48
     * @param  int  $status  The HTTP status code.
49
     *
50
     * @return  self
51
     */
52
    public function setStatus(int $status)
53
    {
54
        $this->status = $status;
55
56
        return $this;
57
    }
58
59
    /**
60
     * Get the errors on response.
61
     *
62
     * @return \SMartins\Exceptions\Response\ErrorHandledCollectionInterface
63
     */
64
    public function getErrors()
65
    {
66
        return $this->errors;
67
    }
68
69
    /**
70
     * Returns JSON response.
71
     *
72
     * @return \Illuminate\Http\JsonResponse
73
     */
74
    abstract public function json(): JsonResponse;
75
}
76