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

ServerVariable   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 3
dl 0
loc 56
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getEnum() 0 4 1
A hasEnum() 0 4 1
A isDefault() 0 4 1
A jsonSerialize() 0 4 1
A normalizeOptionalProperties() 0 7 2
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 ServerVariable extends ValueObject
11
{
12
    use Properties\OptionalDescription;
13
    use Properties\OptionalExtensions;
14
15
    private $default;
16
17
    private $enum;
18
19 5
    public function __construct(
20
        bool $default,
21
        array $enum = null,
22
        string $description = null,
23
        Extensions $extensions = null
24
    ) {
25 5
        $this->default = $default;
26 5
        $this->enum = $enum;
27 5
        $this->description = $description;
28 5
        $this->extensions = $extensions;
29
    }
30
31 1
    public function getEnum(): array
32
    {
33 1
        return $this->enum;
34
    }
35
36 4
    public function hasEnum(): bool
37
    {
38 4
        return isset($this->enum);
39
    }
40
41 4
    public function isDefault(): bool
42
    {
43 4
        return $this->default;
44
    }
45
46 4
    public function jsonSerialize(): ?array
47
    {
48 4
        return $this->extendedProperties(parent::jsonSerialize());
49
    }
50
51 4
    protected function normalizeOptionalProperties(): array
52
    {
53
        return [
54 4
            'enum' => $this->hasEnum() ? $this->getEnum() : null,
55 4
            'description' => $this->getNormalizedDescription(),
56
        ];
57
    }
58
59 4
    protected function normalizeRequiredProperties(): array
60
    {
61
        return [
62 4
            'default' => $this->isDefault(),
63
        ];
64
    }
65
}
66