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

AbstractResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 68
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getErrors() 0 3 1
A setStatus() 0 5 1
A getStatus() 0 3 1
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