Test Failed
Pull Request — master (#34)
by Anatoly
01:58
created

OpenApi::addTag()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router\OpenApi;
13
14
/**
15
 * OAS OpenAPI Object
16
 *
17
 * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#openapi-object
18
 */
19
class OpenApi extends AbstractObject
20
{
21
22
    /**
23
     * @var string
24
     *
25
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oasversion
26
     */
27
    protected $openapi;
28
29
    /**
30
     * @var Info
31
     *
32
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oasinfo
33
     */
34
    protected $info;
35
36
    /**
37
     * @var Server[]
38
     *
39
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oasservers
40
     */
41
    protected $servers = [];
42
43
    /**
44
     * @var array
45
     *
46
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oaspaths
47
     */
48
    protected $paths = [];
49
50
    /**
51
     * @var array
52
     *
53
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oascomponents
54
     */
55
    protected $components = [];
56
57
    /**
58
     * @var SecurityRequirement[]
59
     *
60
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oassecurity
61
     */
62
    protected $security = [];
63
64
    /**
65
     * @var Tag[]
66
     *
67
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oastags
68
     */
69
    protected $tags = [];
70
71
    /**
72
     * @var ExternalDocumentation
73
     *
74
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oasexternaldocs
75
     */
76
    protected $externalDocs;
77
78
    /**
79
     * @param string $openapi
80
     * @param Info $info
81
     */
82
    public function __construct(string $openapi, Info $info)
83
    {
84
        $this->openapi = $openapi;
85
        $this->info = $info;
86
    }
87
88
    /**
89
     * @param Server ...$servers
90
     *
91
     * @return void
92
     */
93
    public function addServer(Server ...$servers) : void
94
    {
95
        foreach ($servers as $server) {
96
            $this->servers[] = $server;
97
        }
98
    }
99
100
    /**
101
     * @param ComponentObjectInterface ...$objects
102
     *
103
     * @return void
104
     */
105
    public function addComponentObject(ComponentObjectInterface ...$objects) : void
106
    {
107
        foreach ($objects as $object) {
108
            $this->components[$object->getComponentName()][$object->getReferenceName()] = $object;
109
        }
110
    }
111
112
    /**
113
     * @param SecurityRequirement ...$requirements
114
     *
115
     * @return void
116
     */
117
    public function addSecurityRequirement(SecurityRequirement ...$requirements) : void
118
    {
119
        foreach ($requirements as $requirement) {
120
            $this->security[] = $requirement;
121
        }
122
    }
123
124
    /**
125
     * @param Tag ...$tags
126
     *
127
     * @return void
128
     */
129
    public function addTag(Tag ...$tags) : void
130
    {
131
        foreach ($tags as $tag) {
132
            $this->tags[] = $tag;
133
        }
134
    }
135
136
    /**
137
     * @param ExternalDocumentation $externalDocs
138
     *
139
     * @return void
140
     */
141
    public function setExternalDocs(ExternalDocumentation $externalDocs) : void
142
    {
143
        $this->externalDocs = $externalDocs;
144
    }
145
}
146