Passed
Pull Request — master (#5)
by Samuel
03:12 queued 01:40
created

ErrorCollection::getHeaders()   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
use SMartins\Exceptions\Response\InvalidContentException;
7
use SMartins\Exceptions\Response\ErrorHandledCollectionInterface;
8
9
class ErrorCollection extends Collection implements ErrorHandledCollectionInterface
10
{
11
    /**
12
     * The HTTP status code applicable to this problem, expressed as a string value.
13
     *
14
     * @var string
15
     */
16
    protected $statusCode;
17
18
    /**
19
     * The HTTP headers on response.
20
     *
21
     * @var array
22
     */
23
    protected $headers = [];
24
25
    /**
26
     * Returns the status code.
27
     *
28
     * @return string|null
29
     */
30
    public function getStatusCode()
31
    {
32
        return $this->statusCode;
33
    }
34
35
    /**
36
     * Returns response headers.
37
     *
38
     * @return array headers
39
     */
40
    public function getHeaders(): array
41
    {
42
        return $this->headers;
43
    }
44
45
    /**
46
     * Set the status code.
47
     *
48
     * @param string $statusCode
49
     *
50
     * @return self
51
     */
52
    public function setStatusCode(string $statusCode)
53
    {
54
        $this->statusCode = $statusCode;
55
56
        return $this;
57
    }
58
59
    /**
60
     * Set the headers of response.
61
     *
62
     * @param array $headers
63
     *
64
     * @return self
65
     */
66
    public function setHeaders(array $headers): self
67
    {
68
        $this->headers = $headers;
69
70
        return $this;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function validatedContent(string $type): ErrorHandledCollectionInterface
77
    {
78
        foreach ($this->items as $item) {
79
            if (! $item instanceof $type) {
80
                throw new InvalidContentException('All items on ['.self::class.'] must to be instances of ['.$type.'].');
81
            }
82
        }
83
84
        return $this;
85
    }
86
}
87