Passed
Pull Request — master (#5)
by Samuel
03:45
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
use SMartins\Exceptions\Response\ErrorHandledInterface;
7
use SMartins\Exceptions\Response\InvalidContentException;
8
use SMartins\Exceptions\Response\ErrorHandledCollectionInterface;
9
10
class ErrorCollection extends Collection implements ErrorHandledCollectionInterface
11
{
12
    /**
13
     * The HTTP status code applicable to this problem, expressed as a string value.
14
     *
15
     * @var string
16
     */
17
    protected $statusCode;
18
19
    /**
20
     * The HTTP headers on response.
21
     *
22
     * @var array
23
     */
24
    protected $headers = [];
25
26
    /**
27
     * Returns the status code.
28
     *
29
     * @return string
30
     */
31
    public function getStatusCode()
32
    {
33
        return $this->statusCode;
34
    }
35
36
    /**
37
     * Returns response headers.
38
     *
39
     * @return array headers
40
     */
41
    public function getHeaders()
42
    {
43
        return $this->headers;
44
    }
45
46
    /**
47
     * Set the status code.
48
     *
49
     * @param string $statusCode
50
     *
51
     * @return self
52
     */
53
    public function setStatusCode(string $statusCode)
54
    {
55
        $this->statusCode = $statusCode;
56
57
        return $this;
58
    }
59
60
    /**
61
     * Set the headers of response.
62
     *
63
     * @param array $headers
64
     * @return self
65
     */
66
    public function setHeaders(array $headers)
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