Completed
Pull Request — master (#3407)
by Antoine
06:51 queued 02:47
created

PathItem::addOperation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\OpenApi;
15
16
class PathItem
17
{
18
    private static $methods = ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH', 'TRACE'];
19
    private $ref;
20
    private $summary;
21
    private $description;
22
    private $getOperation;
23
    private $putOperation;
24
    private $postOperation;
25
    private $deleteOperation;
26
    private $optionsOperation;
27
    private $headOperation;
28
    private $patchOperation;
29
    private $traceOperation;
30
    private $servers;
31
    private $parameters;
32
33
    public function __construct(?string $ref = null, string $summary = '', string $description = '', Operation $getOperation = null, Operation $putOperation = null, Operation $postOperation = null, Operation $deleteOperation = null, Operation $optionsOperation = null, Operation $headOperation = null, Operation $patchOperation = null, Operation $traceOperation = null, array $servers = [], array $parameters = [])
34
    {
35
        $this->ref = $ref;
36
        $this->summary = $summary;
37
        $this->description = $description;
38
        $this->getOperation = $getOperation;
39
        $this->putOperation = $putOperation;
40
        $this->postOperation = $postOperation;
41
        $this->deleteOperation = $deleteOperation;
42
        $this->optionsOperation = $optionsOperation;
43
        $this->headOperation = $headOperation;
44
        $this->patchOperation = $patchOperation;
45
        $this->traceOperation = $traceOperation;
46
        $this->servers = $servers;
47
        $this->parameters = $parameters;
48
    }
49
50
    public function addOperation(string $method, Operation $operation)
51
    {
52
        if (!\in_array($method, self::$methods, true)) {
53
            throw new \InvalidArgumentException(sprintf('Method %s is not supported by OpenAPI in the PathItem as Operation.', $method));
54
        }
55
56
        $this->{strtolower($method).'Operation'} = $operation;
57
    }
58
59
    public function getRef(): ?string
60
    {
61
        return $this->ref;
62
    }
63
64
    public function getSummary(): string
65
    {
66
        return $this->summary;
67
    }
68
69
    public function getDescription(): string
70
    {
71
        return $this->description;
72
    }
73
74
    public function getGetOperation(): ?Operation
75
    {
76
        return $this->getOperation;
77
    }
78
79
    public function getPutOperation(): ?Operation
80
    {
81
        return $this->putOperation;
82
    }
83
84
    public function getPostOperation(): ?Operation
85
    {
86
        return $this->postOperation;
87
    }
88
89
    public function getDeleteOperation(): ?Operation
90
    {
91
        return $this->deleteOperation;
92
    }
93
94
    public function getOptionsOperation(): ?Operation
95
    {
96
        return $this->optionsOperation;
97
    }
98
99
    public function getHeadOperation(): ?Operation
100
    {
101
        return $this->headOperation;
102
    }
103
104
    public function getPatchOperation(): ?Operation
105
    {
106
        return $this->patchOperation;
107
    }
108
109
    public function getTraceOperation(): ?Operation
110
    {
111
        return $this->traceOperation;
112
    }
113
114
    public function getServers(): array
115
    {
116
        return $this->servers;
117
    }
118
119
    public function getParameters(): array
120
    {
121
        return $this->parameters;
122
    }
123
}
124