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

ErrorCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getStatusCode() 0 3 1
A setStatusCode() 0 5 1
A validated() 0 9 3
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