Error::getStatus()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebServCo\Api\JsonApi;
6
7
final class Error
8
{
9
    protected string $id;
10
11
    /**
12
     * Links
13
     *
14
     * @var array<string,string>
15
     */
16
    protected array $links;
17
18
    protected int $status;
19
20
    protected int $code;
21
22
    protected string $title;
23
24
    protected string $detail;
25
26
    protected string $source;
27
28
    /**
29
     * Meta
30
     *
31
     * @var array<string,int|string>
32
     */
33
    protected array $meta;
34
35
    public function __construct()
36
    {
37
        $this->meta = [];
38
    }
39
40
    public function getStatus(): int
41
    {
42
        return $this->status;
43
    }
44
45
    public function setStatus(int $status): bool
46
    {
47
        $this->status = $status;
48
        return true;
49
    }
50
51
    public function setTitle(string $title): bool
52
    {
53
        $this->title = $title;
54
        return true;
55
    }
56
57
    public function setDetail(string $detail): bool
58
    {
59
        $this->detail = $detail;
60
        return true;
61
    }
62
63
    public function setMeta(string $key, string $value): bool
64
    {
65
        $this->meta[$key] = $value;
66
        return true;
67
    }
68
69
    /**
70
    * @return array<string,mixed>
71
    */
72
    public function toArray(): array
73
    {
74
        $array = [];
75
        foreach (\get_object_vars($this) as $key => $value) {
76
            if (empty($value)) {
77
                continue;
78
            }
79
80
            $array[$key] = $value;
81
        }
82
        return $array;
83
    }
84
}
85