Conditions | 1 |
Paths | 1 |
Total Lines | 106 |
Code Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
127 | public function testHandleCommand_MethodOrdering() |
||
128 | { |
||
129 | $object = new \SwaggerGen\Swagger\Path($this->parent, new SwaggerGen\Swagger\Tag($this->parent, 'Tag')); |
||
130 | $this->assertInstanceOf('\SwaggerGen\Swagger\Path', $object); |
||
131 | |||
132 | $operation = $object->handleCommand('method', 'post'); |
||
133 | $this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
||
134 | $operation->handleCommand('response', 200); |
||
135 | |||
136 | $operation = $object->handleCommand('method', 'delete'); |
||
137 | $this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
||
138 | $operation->handleCommand('response', 200); |
||
139 | |||
140 | $operation = $object->handleCommand('method', 'patch'); |
||
141 | $this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
||
142 | $operation->handleCommand('response', 200); |
||
143 | |||
144 | $operation = $object->handleCommand('method', 'put'); |
||
145 | $this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
||
146 | $operation->handleCommand('response', 200); |
||
147 | |||
148 | $operation = $object->handleCommand('method', 'head'); |
||
149 | $this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
||
150 | $operation->handleCommand('response', 200); |
||
151 | |||
152 | $operation = $object->handleCommand('method', 'get'); |
||
153 | $this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
||
154 | $operation->handleCommand('response', 200); |
||
155 | |||
156 | $operation = $object->handleCommand('method', 'options'); |
||
157 | $this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
||
158 | $operation->handleCommand('response', 200); |
||
159 | |||
160 | $this->assertSame(array( |
||
161 | 'get' => array( |
||
162 | 'tags' => array( |
||
163 | 'Tag', |
||
164 | ), |
||
165 | 'responses' => array( |
||
166 | 200 => array( |
||
167 | 'description' => 'OK', |
||
168 | ), |
||
169 | ), |
||
170 | ), |
||
171 | 'put' => array( |
||
172 | 'tags' => array( |
||
173 | 'Tag', |
||
174 | ), |
||
175 | 'responses' => array( |
||
176 | 200 => array( |
||
177 | 'description' => 'OK', |
||
178 | ), |
||
179 | ), |
||
180 | ), |
||
181 | 'post' => array( |
||
182 | 'tags' => array( |
||
183 | 'Tag', |
||
184 | ), |
||
185 | 'responses' => array( |
||
186 | 200 => array( |
||
187 | 'description' => 'OK', |
||
188 | ), |
||
189 | ), |
||
190 | ), |
||
191 | 'delete' => array( |
||
192 | 'tags' => array( |
||
193 | 'Tag', |
||
194 | ), |
||
195 | 'responses' => array( |
||
196 | 200 => array( |
||
197 | 'description' => 'OK', |
||
198 | ), |
||
199 | ), |
||
200 | ), |
||
201 | 'options' => array( |
||
202 | 'tags' => array( |
||
203 | 'Tag', |
||
204 | ), |
||
205 | 'responses' => array( |
||
206 | 200 => array( |
||
207 | 'description' => 'OK', |
||
208 | ), |
||
209 | ), |
||
210 | ), |
||
211 | 'head' => array( |
||
212 | 'tags' => array( |
||
213 | 'Tag', |
||
214 | ), |
||
215 | 'responses' => array( |
||
216 | 200 => array( |
||
217 | 'description' => 'OK', |
||
218 | ), |
||
219 | ), |
||
220 | ), |
||
221 | 'patch' => array( |
||
222 | 'tags' => array( |
||
223 | 'Tag', |
||
224 | ), |
||
225 | 'responses' => array( |
||
226 | 200 => array( |
||
227 | 'description' => 'OK', |
||
228 | ), |
||
229 | ), |
||
230 | ), |
||
231 | ), $object->toArray()); |
||
232 | } |
||
233 | |||
235 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.