Passed
Push — 2.0 ( 6127f1...6cb80b )
by Samuel
02:33
created

ErrorCollection::getStatusCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SMartins\Exceptions\JsonApi;
4
5
use Illuminate\Support\Collection;
6
7
class ErrorCollection extends Collection
8
{
9
    /**
10
     * The HTTP status code applicable to this problem, expressed as a string value.
11
     *
12
     * @var string
13
     */
14
    protected $statusCode;
15
16
    /**
17
     * The HTTP headers on response.
18
     *
19
     * @var array
20
     */
21
    protected $headers = [];
22
23
    /**
24
     * Returns the status code.
25
     *
26
     * @return string
27
     */
28
    public function getStatusCode()
29
    {
30
        return $this->statusCode;
31
    }
32
33
    /**
34
     * Returns response headers.
35
     *
36
     * @return array headers
37
     */
38
    public function getHeaders()
39
    {
40
        return $this->headers;
41
    }
42
43
    /**
44
     * Set the status code.
45
     *
46
     * @param string $statusCode
47
     *
48
     * @return self
49
     */
50
    public function setStatusCode(string $statusCode)
51
    {
52
        $this->statusCode = $statusCode;
53
54
        return $this;
55
    }
56
57
    /**
58
     * Set the headers of response.
59
     *
60
     * @param array $headers
61
     * @return self
62
     */
63
    public function setHeaders(array $headers)
64
    {
65
        $this->headers = $headers;
66
67
        return $this;
68
    }
69
70
    /**
71
     * Validate the content of items. All item should to be an instances of Error.
72
     *
73
     * @return self
74
     *
75
     * @throws \SMartins\Exceptions\JsonApi\InvalidContentException
76
     */
77
    public function validated()
78
    {
79
        foreach ($this->items as $item) {
80
            if ($item instanceof Error === false) {
81
                throw new InvalidContentException('All items on '.self::class.' must to be instances of '.Error::class, 1);
82
            }
83
        }
84
85
        return $this;
86
    }
87
}
88