1 | <?php |
||
11 | class Parameters extends AbstractModel implements Arrayable, \Iterator { |
||
12 | |||
13 | use RefPart; |
||
14 | |||
15 | /** @var ArrayList */ |
||
16 | private $parameters; |
||
17 | |||
18 | 12 | public function __construct($contents = []) { |
|
21 | |||
22 | 12 | private function parse($contents) { |
|
23 | 12 | $data = CollectionUtils::toMap($contents); |
|
24 | |||
25 | 12 | $this->parameters = new ArrayList(); |
|
26 | 12 | $this->parseRef($data); |
|
27 | |||
28 | 12 | if (!$this->hasRef()) { |
|
29 | 12 | foreach ($data as $param) { |
|
30 | 4 | $this->parameters->add(new Parameter($param)); |
|
31 | } |
||
32 | } |
||
33 | 12 | } |
|
34 | |||
35 | 8 | public function toArray() { |
|
42 | |||
43 | 1 | public function size() { |
|
46 | |||
47 | /** |
||
48 | * Searches whether a parameter with the given name exists |
||
49 | * |
||
50 | * @param string $name |
||
51 | * @return bool |
||
52 | */ |
||
53 | 1 | public function searchByName($name) { |
|
58 | |||
59 | /** |
||
60 | * Returns parameter with the given name if it exists |
||
61 | * |
||
62 | * @param string $name |
||
63 | * @return Parameter|void |
||
64 | */ |
||
65 | 1 | public function findByName($name) { |
|
66 | 1 | foreach ($this->parameters as $param) { |
|
67 | 1 | if ($param->getName() == $name) { |
|
68 | 1 | return $param; |
|
69 | } |
||
70 | } |
||
71 | 1 | } |
|
72 | |||
73 | /** |
||
74 | * Searches for the parameter with the given name. Creates a parameter with the given name |
||
75 | * if none exists |
||
76 | * |
||
77 | * @param string $name |
||
78 | * @return Parameter |
||
79 | */ |
||
80 | public function getByName($name) { |
||
81 | $param = $this->findByName($name); |
||
82 | if (empty($param)) { |
||
83 | $param = new Parameter(); |
||
84 | $param->setName($name); |
||
85 | $this->parameters->add($param); |
||
86 | } |
||
87 | |||
88 | return $param; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Searches whether a parameter with the given unique combination exists |
||
93 | * |
||
94 | * @param string $name |
||
95 | * @param string $id |
||
|
|||
96 | * @return bool |
||
97 | */ |
||
98 | public function search($name, $in) { |
||
103 | |||
104 | 1 | public function find($name, $in) { |
|
105 | 1 | foreach ($this->parameters as $param) { |
|
106 | 1 | if ($param->getIn() == $in && $param->getName() == $name) { |
|
107 | 1 | return $param; |
|
108 | } |
||
109 | } |
||
110 | 1 | } |
|
111 | |||
112 | 1 | public function get($name, $in) { |
|
113 | 1 | $param = $this->find($name, $in); |
|
114 | 1 | if (empty($param)) { |
|
115 | 1 | $param = new Parameter(); |
|
116 | 1 | $param->setName($name); |
|
117 | 1 | $param->setIn($in); |
|
118 | 1 | $this->parameters->add($param); |
|
119 | } |
||
120 | |||
121 | 1 | return $param; |
|
122 | } |
||
123 | |||
124 | /** |
||
125 | * Adds a parameter |
||
126 | * |
||
127 | * @param Parameter $param |
||
128 | */ |
||
129 | 1 | public function add(Parameter $param) { |
|
132 | |||
133 | /** |
||
134 | * Removes a parameter |
||
135 | * |
||
136 | * @param Parameter $param |
||
137 | */ |
||
138 | 1 | public function remove(Parameter $param) { |
|
141 | |||
142 | /** |
||
143 | * Returns whether a given parameter exists |
||
144 | * |
||
145 | * @param Parameter $param |
||
146 | * @return bool |
||
147 | */ |
||
148 | 1 | public function contains(Parameter $param) { |
|
151 | |||
152 | public function current() { |
||
155 | |||
156 | public function key() { |
||
159 | |||
160 | public function next() { |
||
163 | |||
164 | public function rewind() { |
||
167 | |||
168 | public function valid() { |
||
171 | } |
||
172 |
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.