1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace gossi\swagger\collections; |
4
|
|
|
|
5
|
|
|
use gossi\swagger\Schema; |
6
|
|
|
use phootwork\collection\CollectionUtils; |
7
|
|
|
use phootwork\lang\Arrayable; |
8
|
|
|
use phootwork\collection\Map; |
9
|
|
|
|
10
|
|
|
class Definitions implements Arrayable, \Iterator |
11
|
|
|
{ |
12
|
|
|
/** @var Map */ |
13
|
|
|
private $definitions; |
14
|
|
|
|
15
|
12 |
|
public function __construct($contents = []) |
16
|
|
|
{ |
17
|
12 |
|
$this->parse($contents === null ? [] : $contents); |
18
|
12 |
|
} |
19
|
|
|
|
20
|
12 |
|
private function parse($contents) |
21
|
|
|
{ |
22
|
12 |
|
$data = CollectionUtils::toMap($contents); |
23
|
|
|
|
24
|
12 |
|
$this->definitions = new Map(); |
25
|
12 |
|
foreach ($data as $name => $prop) { |
26
|
6 |
|
$this->definitions->set($name, new Schema($prop)); |
27
|
12 |
|
} |
28
|
12 |
|
} |
29
|
|
|
|
30
|
7 |
|
public function toArray() |
31
|
|
|
{ |
32
|
7 |
|
return $this->definitions->toArray(); |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
public function size() |
36
|
|
|
{ |
37
|
1 |
|
return $this->definitions->size(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns the schema for the given field. |
42
|
|
|
* |
43
|
|
|
* @param string $name |
44
|
|
|
* |
45
|
|
|
* @return Schema |
46
|
|
|
*/ |
47
|
1 |
|
public function get($name) |
48
|
|
|
{ |
49
|
1 |
|
if (!$this->definitions->has($name)) { |
50
|
|
|
$this->definitions->set($name, new Schema()); |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
return $this->definitions->get($name); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Sets the field. |
58
|
|
|
* |
59
|
|
|
* @param string name |
60
|
|
|
* @param Schema $schame |
|
|
|
|
61
|
|
|
*/ |
62
|
1 |
|
public function set($name, Schema $schema) |
63
|
|
|
{ |
64
|
1 |
|
$this->definitions->set($name, $schema); |
65
|
1 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Removes the given field. |
69
|
|
|
* |
70
|
|
|
* @param string $name |
71
|
|
|
*/ |
72
|
1 |
|
public function remove($name) |
73
|
|
|
{ |
74
|
1 |
|
$this->definitions->remove($name); |
75
|
1 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns definitions has a schema with the given name. |
79
|
|
|
* |
80
|
|
|
* @param string $name |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
1 |
|
public function has($name) |
85
|
|
|
{ |
86
|
1 |
|
return $this->definitions->has($name); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Returns whether the given schema exists. |
91
|
|
|
* |
92
|
|
|
* @param Schema $schema |
93
|
|
|
* |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
1 |
|
public function contains(Schema $schema) |
97
|
|
|
{ |
98
|
1 |
|
return $this->definitions->contains($schema); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function current() |
102
|
|
|
{ |
103
|
|
|
return $this->definitions->current(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function key() |
107
|
|
|
{ |
108
|
|
|
return $this->definitions->key(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function next() |
112
|
|
|
{ |
113
|
|
|
return $this->definitions->next(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function rewind() |
117
|
|
|
{ |
118
|
|
|
return $this->definitions->rewind(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function valid() |
122
|
|
|
{ |
123
|
|
|
return $this->definitions->valid(); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.