1
|
|
|
<?php |
2
|
|
|
namespace gossi\swagger\collections; |
3
|
|
|
|
4
|
|
|
use gossi\swagger\parts\ExtensionPart; |
5
|
|
|
use gossi\swagger\Response; |
6
|
|
|
use phootwork\collection\CollectionUtils; |
7
|
|
|
use phootwork\collection\Map; |
8
|
|
|
use phootwork\lang\Arrayable; |
9
|
|
|
use phootwork\lang\Text; |
10
|
|
|
|
11
|
|
|
class Responses implements Arrayable, \Iterator { |
12
|
|
|
|
13
|
|
|
use ExtensionPart; |
14
|
|
|
|
15
|
|
|
/** @var Map */ |
16
|
|
|
private $responses; |
17
|
|
|
|
18
|
12 |
|
public function __construct($contents = []) { |
19
|
12 |
|
$this->parse($contents === null ? [] : $contents); |
20
|
12 |
|
} |
21
|
|
|
|
22
|
12 |
|
private function parse($contents) { |
23
|
12 |
|
$data = CollectionUtils::toMap($contents); |
24
|
|
|
|
25
|
|
|
// responses |
26
|
12 |
|
$this->responses = new Map(); |
27
|
12 |
|
foreach ($data as $r => $response) { |
28
|
6 |
|
if (!Text::create($r)->startsWith('x-')) { |
29
|
6 |
|
$this->responses->set($r, new Response($r, $response)); |
30
|
6 |
|
} |
31
|
12 |
|
} |
32
|
|
|
|
33
|
|
|
// extensions |
34
|
12 |
|
$this->parseExtensions($data); |
35
|
12 |
|
} |
36
|
|
|
|
37
|
7 |
|
public function toArray() { |
38
|
7 |
|
$responses = clone $this->responses; |
39
|
7 |
|
$responses->setAll($this->getExtensions()); |
40
|
7 |
|
return $responses->toArray(); |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
public function size() { |
44
|
1 |
|
return $this->responses->size(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns whether the given response exists |
49
|
|
|
* |
50
|
|
|
* @param string $code |
51
|
|
|
* @return boolean |
52
|
|
|
*/ |
53
|
1 |
|
public function has($code) { |
54
|
1 |
|
return $this->responses->has($code); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Returns whether the given response exists |
59
|
|
|
* |
60
|
|
|
* @param Response $response |
61
|
|
|
* @return boolean |
62
|
|
|
*/ |
63
|
1 |
|
public function contains(Response $response) { |
64
|
1 |
|
return $this->responses->contains($response); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns the reponse info for the given code |
69
|
|
|
* |
70
|
|
|
* @param string $code |
71
|
|
|
* @return Response |
72
|
|
|
*/ |
73
|
8 |
|
public function get($code) { |
74
|
8 |
|
if (!$this->responses->has($code)) { |
75
|
|
|
$this->responses->set($code, new Response($code)); |
76
|
|
|
} |
77
|
|
|
|
78
|
2 |
|
return $this->responses->get($code); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Sets the response |
83
|
|
|
* |
84
|
|
|
* @param Response $code |
|
|
|
|
85
|
|
|
*/ |
86
|
1 |
|
public function add(Response $response) { |
87
|
1 |
|
$this->responses->set($response->getCode(), $response); |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Removes the given repsonse |
92
|
|
|
* |
93
|
|
|
* @param string $code |
94
|
|
|
*/ |
95
|
1 |
|
public function remove($code) { |
96
|
1 |
|
$this->responses->remove($code); |
97
|
1 |
|
} |
98
|
|
|
|
99
|
|
|
public function current() { |
100
|
|
|
return $this->responses->current(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function key() { |
104
|
|
|
return $this->responses->key(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function next() { |
108
|
|
|
return $this->responses->next(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function rewind() { |
112
|
|
|
return $this->responses->rewind(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function valid() { |
116
|
|
|
return $this->responses->valid(); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
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.