34
34
*
35
35
* @link https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/versions/3.0.2.md#pathsObject
36
36
*
37
- * @implements ArrayAccess<string, PathItem|null >
38
- * @implements IteratorAggregate<string, PathItem|null >
37
+ * @implements ArrayAccess<string, PathItem>
38
+ * @implements IteratorAggregate<string, PathItem>
39
39
*/
40
40
class Paths implements SpecObjectInterface, DocumentContextInterface, ArrayAccess, Countable, IteratorAggregate
41
41
{
42
- /** @var array<string, PathItem|null > */
42
+ /** @var array<string, PathItem> */
43
43
private array $ _paths = [];
44
44
/** @var list<string> */
45
45
private array $ _errors = [];
@@ -57,11 +57,11 @@ public function __construct(array $data)
57
57
{
58
58
foreach ($ data as $ path => $ object ) {
59
59
if ($ object === null ) {
60
- $ this ->_paths [ $ path] = null ;
60
+ $ this ->removePath ( $ path) ;
61
61
} elseif (is_array ($ object )) {
62
- $ this ->_paths [ $ path] = new PathItem ($ object );
62
+ $ this ->addPath ( $ path, new PathItem ($ object) );
63
63
} elseif ($ object instanceof PathItem) {
64
- $ this ->_paths [ $ path] = $ object ;
64
+ $ this ->addPath ( $ path, $ object) ;
65
65
} else {
66
66
$ givenType = gettype ($ object );
67
67
if (is_object ($ object )) {
@@ -81,7 +81,7 @@ public function getSerializableData(): object
81
81
{
82
82
$ data = [];
83
83
foreach ($ this ->_paths as $ path => $ pathItem ) {
84
- $ data [$ path ] = $ pathItem? ->getSerializableData();
84
+ $ data [$ path ] = $ pathItem ->getSerializableData ();
85
85
}
86
86
87
87
return (object ) $ data ;
@@ -115,10 +115,14 @@ public function addPath(string $name, PathItem $pathItem): void
115
115
/** @param string $name path name */
116
116
public function removePath (string $ name ): void
117
117
{
118
+ if (! $ this ->hasPath ($ name )) {
119
+ return ;
120
+ }
121
+
118
122
unset($ this ->_paths [$ name ]);
119
123
}
120
124
121
- /** @return array<string, PathItem|null > */
125
+ /** @return array<string, PathItem> */
122
126
public function getPaths (): array
123
127
{
124
128
return $ this ->_paths ;
@@ -136,10 +140,6 @@ public function validate(): bool
136
140
$ valid = true ;
137
141
$ this ->_errors = [];
138
142
foreach ($ this ->_paths as $ key => $ path ) {
139
- if ($ path === null ) {
140
- continue ;
141
- }
142
-
143
143
if (! $ path ->validate ()) {
144
144
$ valid = false ;
145
145
}
@@ -169,10 +169,6 @@ public function getErrors(): array
169
169
}
170
170
171
171
foreach ($ this ->_paths as $ path ) {
172
- if ($ path === null ) {
173
- continue ;
174
- }
175
-
176
172
$ errors [] = $ path ->getErrors ();
177
173
}
178
174
@@ -267,7 +263,7 @@ public function count(): int
267
263
*
268
264
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
269
265
*
270
- * @return Traversable<PathItem|null > An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>
266
+ * @return Traversable<PathItem> An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>
271
267
*/
272
268
public function getIterator (): Traversable
273
269
{
@@ -282,10 +278,6 @@ public function getIterator(): Traversable
282
278
public function resolveReferences (ReferenceContext |null $ context = null ): void
283
279
{
284
280
foreach ($ this ->_paths as $ path ) {
285
- if ($ path === null ) {
286
- continue ;
287
- }
288
-
289
281
$ path ->resolveReferences ($ context );
290
282
}
291
283
}
@@ -296,10 +288,6 @@ public function resolveReferences(ReferenceContext|null $context = null): void
296
288
public function setReferenceContext (ReferenceContext $ context ): void
297
289
{
298
290
foreach ($ this ->_paths as $ path ) {
299
- if ($ path === null ) {
300
- continue ;
301
- }
302
-
303
291
$ path ->setReferenceContext ($ context );
304
292
}
305
293
}
0 commit comments