Completed
Pull Request — master (#4)
by Veaceslav
02:34
created

Response   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 6
dl 0
loc 65
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A getHeaders() 0 4 1
A getLinks() 0 4 1
A hasHeaders() 0 4 1
A hasLinks() 0 4 1
A jsonSerialize() 0 4 1
A normalizeOptionalProperties() 0 8 3
A normalizeRequiredProperties() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aweapi\Openapi\Objects;
6
7
use Aweapi\Openapi\Extensions;
8
use Aweapi\Openapi\ValueObject;
9
10
final class Response extends ValueObject implements ResponseAggregate
11
{
12
    use Properties\Description;
13
    use Properties\OptionalMediaTypeContent;
14
    use Properties\OptionalExtensions;
15
16
    private $headers;
17
18
    private $links;
19
20 8
    public function __construct(
21
        string $description,
22
        Headers $headers = null,
23
        MediaTypes $content = null,
24
        Links $links = null,
25
        Extensions $extensions = null
26
    ) {
27 8
        $this->description = $description;
28 8
        $this->headers = $headers;
29 8
        $this->content = $content;
30 8
        $this->links = $links;
31 8
        $this->extensions = $extensions;
32
    }
33
34 1
    public function getHeaders(): Headers
35
    {
36 1
        return $this->headers;
37
    }
38
39 1
    public function getLinks(): Links
40
    {
41 1
        return $this->links;
42
    }
43
44 7
    public function hasHeaders(): bool
45
    {
46 7
        return isset($this->headers);
47
    }
48
49 7
    public function hasLinks(): bool
50
    {
51 7
        return isset($this->links);
52
    }
53
54 7
    public function jsonSerialize(): ?array
55
    {
56 7
        return $this->extendedProperties(parent::jsonSerialize());
57
    }
58
59 7
    protected function normalizeOptionalProperties(): array
60
    {
61
        return [
62 7
            'headers' => $this->hasHeaders() ? $this->getHeaders()->jsonSerialize() : null,
63 7
            'content' => $this->getNormalizedContent(),
64 7
            'links' => $this->hasLinks() ? $this->getLinks()->jsonSerialize() : null,
65
        ];
66
    }
67
68 7
    protected function normalizeRequiredProperties(): array
69
    {
70
        return [
71 7
            'description' => $this->getDescription(),
72
        ];
73
    }
74
}
75