Passed
Push — 2.0 ( 50041b...cfd0e0 )
by Samuel
02:05
created

ErrorCollection::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace SMartins\Exceptions\JsonApi;
4
5
use InvalidArgumentException;
6
use Illuminate\Support\Collection;
7
8
class ErrorCollection extends Collection
9
{
10
    /**
11
     * The HTTP status code applicable to this problem, expressed as a string value.
12
     *
13
     * @var string
14
     */
15
    protected $statusCode;
16
17
    /**
18
     * Get the status code.
19
     *
20
     * @return string
21
     */
22
    public function getStatusCode()
23
    {
24
        return $this->statusCode;
25
    }
26
27
    /**
28
     * Set the status code.
29
     *
30
     * @param string $statusCode
31
     *
32
     * @return self
33
     */
34
    public function setStatusCode(string $statusCode)
35
    {
36
        $this->statusCode = $statusCode;
37
38
        return $this;
39
    }
40
41
    /**
42
     * Validate the content of items. All item should to be an instances of Error.
43
     *
44
     * @return self
45
     *
46
     * @throws \SMartins\Exceptions\JsonApi\CollectionInvalidContent
47
     */
48
    public function validated()
49
    {
50
        foreach ($this->items as $item) {
51
            if ($item instanceof Error === false) {
52
                throw new InvalidContentException('All items on '.self::class.' must to be instances of '.Error::class, 1);
53
            }
54
        }
55
56
        return $this;
57
    }
58
}
59