Link::getServer()   A
last analyzed

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
use InvalidArgumentException;
10
11
final class Link extends ValueObject implements LinkAggregate
12
{
13
    use Properties\OptionalDescription;
14
    use Properties\OptionalExtensions;
15
16
    private $operationId;
17
18
    private $operationRef;
19
20
    private $parameters;
21
22
    private $requestBody;
23
24
    private $server;
25
26
    /**
27
     * @param mixed $requestBody
28
     */
29 13
    public function __construct(
30
        string $operationId = null,
31
        string $operationRef = null,
32
        string $description = null,
33
        array $parameters = [],
34
        $requestBody = null,
35
        Server $server = null,
36
        Extensions $extensions = null
37
    ) {
38 13
        if (!empty($operationId) && !empty($operationRef)) {
39 1
            throw new InvalidArgumentException('The Link operationId and operationRef are mutually exclusive');
40
        }
41
42 12
        if (empty($operationId) && empty($operationRef)) {
43 1
            throw new InvalidArgumentException('The Link must have either operationId or operationRef');
44
        }
45
46 11
        $this->operationId = $operationId;
47 11
        $this->operationRef = $operationRef;
48 11
        $this->description = $description;
49 11
        $this->parameters = $parameters;
50 11
        $this->requestBody = $requestBody;
51 11
        $this->server = $server;
52 11
        $this->extensions = $extensions;
53
    }
54
55 8
    public function getOperationId(): string
56
    {
57 8
        return $this->operationId;
58
    }
59
60 2
    public function getOperationRef(): string
61
    {
62 2
        return $this->operationRef;
63
    }
64
65 10
    public function getParameters(): array
66
    {
67 10
        return $this->parameters;
68
    }
69
70
    /**
71
     * @return mixed
72
     */
73 10
    public function getRequestBody()
74
    {
75 10
        return $this->requestBody;
76
    }
77
78 2
    public function getServer(): Server
79
    {
80 2
        return $this->server;
81
    }
82
83 10
    public function hasOperationId(): bool
84
    {
85 10
        return isset($this->operationId);
86
    }
87
88 10
    public function hasOperationRef(): bool
89
    {
90 10
        return isset($this->operationRef);
91
    }
92
93 10
    public function hasServer(): bool
94
    {
95 10
        return isset($this->server);
96
    }
97
98 10
    public function jsonSerialize(): ?array
99
    {
100 10
        return $this->extendedProperties(parent::jsonSerialize());
101
    }
102
103 10
    protected function normalizeOptionalProperties(): array
104
    {
105
        return [
106 10
            'operationId' => $this->hasOperationId() ? $this->getOperationId() : null,
107 10
            'operationRef' => $this->hasOperationRef() ? $this->getOperationRef() : null,
108 10
            'description' => $this->getNormalizedDescription(),
109 10
            'parameters' => $this->getParameters(),
110 10
            'requestBody' => $this->getRequestBody(),
111 10
            'server' => $this->hasServer() ? $this->getServer() : null,
112
        ];
113
    }
114
}
115