ProblemDetails   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 84
ccs 13
cts 21
cp 0.619
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getTitle() 0 4 1
A getStatus() 0 4 1
A getDetail() 0 4 1
A getExtensions() 0 4 1
A jsonSerialize() 0 4 1
A toArray() 0 8 1
1
<?php declare(strict_types=1);
2
3
namespace HSkrasek\JSONSchema;
4
5
final class ProblemDetails implements \JsonSerializable
6
{
7
    /**
8
     * @var string
9
     */
10
    private $title;
11
12
    /**
13
     * @var int
14
     */
15
    private $status;
16
17
    /**
18
     * @var string|null
19
     */
20
    private $detail;
21
22
    /**
23
     * @var array
24
     */
25
    private $extensions;
26
27 9
    public function __construct(string $title, int $status, ?string $detail, array $extensions = [])
28
    {
29 9
        $this->title      = $title;
30 9
        $this->status     = $status;
31 9
        $this->detail     = $detail;
32 9
        $this->extensions = $extensions;
33 9
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getTitle(): string
39
    {
40
        return $this->title;
41
    }
42
43
    /**
44
     * @return int
45
     */
46
    public function getStatus(): int
47
    {
48
        return $this->status;
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getDetail(): string
55
    {
56
        return $this->detail;
57
    }
58
59
    /**
60
     * @return array
61
     */
62 3
    public function getExtensions(): array
63
    {
64 3
        return $this->extensions;
65
    }
66
67
    /**
68
     * Specify data which should be serialized to JSON
69
     *
70
     * @link  http://php.net/manual/en/jsonserializable.jsonserialize.php
71
     * @return mixed data which can be serialized by <b>json_encode</b>,
72
     * which is a value of any type other than a resource.
73
     * @since 5.4.0
74
     */
75
    public function jsonSerialize()
76
    {
77
        return $this->toArray();
78
    }
79
80 6
    public function toArray(): array
81
    {
82
        return [
83 6
                'title'  => $this->title,
84 6
                'detail' => $this->detail,
85 6
                'status' => $this->status,
86 6
            ] + $this->extensions;
87
    }
88
}
89