Completed
Push — master ( 935a4f...80b369 )
by Veaceslav
01:53
created

Server::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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 Server extends ValueObject
11
{
12
    use Properties\OptionalDescription;
13
    use Properties\OptionalExtensions;
14
15
    private $url;
16
17
    private $variables;
18
19 8
    public function __construct(
20
        string $url,
21
        string $description = null,
22
        ServerVariables $variables = null,
23
        Extensions $extensions = null
24
    ) {
25 8
        $this->url = $url;
26 8
        $this->description = $description;
27 8
        $this->variables = $variables;
28 8
        $this->extensions = $extensions;
29
    }
30
31 8
    public function getUrl(): string
32
    {
33 8
        return $this->url;
34
    }
35
36 1
    public function getVariables(): ServerVariables
37
    {
38 1
        return $this->variables;
39
    }
40
41 8
    public function hasVariables(): bool
42
    {
43 8
        return isset($this->variables);
44
    }
45
46 8
    public function jsonSerialize(): ?array
47
    {
48 8
        return $this->extendedProperties(parent::jsonSerialize());
49
    }
50
51 8
    protected function normalizeOptionalProperties(): array
52
    {
53
        return [
54 8
            'description' => $this->getNormalizedDescription(),
55 8
            'variables' => $this->hasVariables() ? $this->getVariables()->jsonSerialize() : null,
56
        ];
57
    }
58
59 8
    protected function normalizeRequiredProperties(): array
60
    {
61
        return [
62 8
            'url' => $this->getUrl(),
63
        ];
64
    }
65
}
66