Conditions | 1 |
Paths | 1 |
Total Lines | 274 |
Code Lines | 189 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
81 | public function routeProvider(){ |
||
82 | return array( |
||
83 | // test invalid HTTP type |
||
84 | array( |
||
85 | "command::join::response", |
||
86 | array(), |
||
87 | array( |
||
88 | "type" => "command::join::response", |
||
89 | "data" => array( |
||
90 | "status" => "error", |
||
91 | "msg" => ApiController::INVALID_HTTP_TYPE |
||
92 | ) |
||
93 | ) |
||
94 | ), |
||
95 | // test ommitted session id |
||
96 | array( |
||
97 | "command::blub::request", |
||
98 | array(), |
||
99 | array( |
||
100 | "type" => "command::blub::response", |
||
101 | "data" => array( |
||
102 | "status" => "error", |
||
103 | "msg" => ApiController::NO_SESSION_ID |
||
104 | ) |
||
105 | ) |
||
106 | ), |
||
107 | // test ommited user |
||
108 | array( |
||
109 | "command::blub::request", |
||
110 | array( |
||
111 | "session_id" => md5(time()) |
||
112 | ), |
||
113 | array( |
||
114 | "type" => "command::blub::response", |
||
115 | "data" => array( |
||
116 | "status" => "error", |
||
117 | "msg" => ApiController::NO_USER |
||
118 | ) |
||
119 | ) |
||
120 | ), |
||
121 | // test invalid http type with data as requesttype |
||
122 | array( |
||
123 | "data::join::response", |
||
124 | array(), |
||
125 | array( |
||
126 | "type" => "data::join::response", |
||
127 | "data" => array( |
||
128 | "status" => "error", |
||
129 | "msg" => ApiController::INVALID_HTTP_TYPE |
||
130 | ) |
||
131 | ) |
||
132 | ), |
||
133 | // test ommitted session id with data as requesttype |
||
134 | array( |
||
135 | "data::blub::request", |
||
136 | array(), |
||
137 | array( |
||
138 | "type" => "data::blub::response", |
||
139 | "data" => array( |
||
140 | "status" => "error", |
||
141 | "msg" => ApiController::NO_SESSION_ID |
||
142 | ) |
||
143 | ) |
||
144 | ), |
||
145 | // test ommitted user with data as requesttype |
||
146 | array( |
||
147 | "data::blub::request", |
||
148 | array( |
||
149 | "session_id" => md5(time()) |
||
150 | ), |
||
151 | array( |
||
152 | "type" => "data::blub::response", |
||
153 | "data" => array( |
||
154 | "status" => "error", |
||
155 | "msg" => ApiController::NO_USER |
||
156 | ) |
||
157 | ) |
||
158 | ), |
||
159 | // test invalid http type with push as requesttype |
||
160 | array( |
||
161 | "push::join::response", |
||
162 | array(), |
||
163 | array( |
||
164 | "type" => "push::join::response", |
||
165 | "data" => array( |
||
166 | "status" => "error", |
||
167 | "msg" => ApiController::INVALID_HTTP_TYPE |
||
168 | ) |
||
169 | ) |
||
170 | ), |
||
171 | // test ommitted session id with push as requesttype |
||
172 | array( |
||
173 | "push::blub::request", |
||
174 | array(), |
||
175 | array( |
||
176 | "type" => "push::blub::response", |
||
177 | "data" => array( |
||
178 | "status" => "error", |
||
179 | "msg" => ApiController::NO_SESSION_ID |
||
180 | ) |
||
181 | ) |
||
182 | ), |
||
183 | // test ommitted user with push as requesttype |
||
184 | array( |
||
185 | "push::blub::request", |
||
186 | array( |
||
187 | "session_id" => md5(time()) |
||
188 | ), |
||
189 | array( |
||
190 | "type" => "push::blub::response", |
||
191 | "data" => array( |
||
192 | "status" => "error", |
||
193 | "msg" => ApiController::NO_USER |
||
194 | ) |
||
195 | ) |
||
196 | ), |
||
197 | // test not existent command |
||
198 | array( |
||
199 | "command::blub::request", |
||
200 | array( |
||
201 | "session_id" => md5(time()), |
||
202 | "user" => array( |
||
203 | 'id' => 'foo', |
||
204 | 'displayname' => 'foo', |
||
205 | 'backends' => array ( |
||
206 | 'email' => array ( |
||
207 | 'id' => NULL, |
||
208 | 'displayname' => 'E-mail', |
||
209 | 'protocol' => 'email', |
||
210 | 'namespace' => ' email', |
||
211 | 'value' => array ( |
||
212 | 0 => array ( |
||
213 | ), |
||
214 | ), |
||
215 | ), |
||
216 | 'och' => array ( |
||
217 | 'id' => NULL, |
||
218 | 'displayname' => 'ownCloud Handle', |
||
219 | 'protocol' => 'x-owncloud-handle', |
||
220 | 'namespace' => 'och', |
||
221 | 'value' => 'foo', |
||
222 | ), |
||
223 | ), |
||
224 | 'address_book_id' => 'local', |
||
225 | 'address_book_backend' => '', |
||
226 | ), |
||
227 | ), |
||
228 | array( |
||
229 | "type" => "command::blub::response", |
||
230 | "data" => array( |
||
231 | "status" => "error", |
||
232 | "msg" => ApiController::COMMAND_NOT_FOUND |
||
233 | ) |
||
234 | ) |
||
235 | ), |
||
236 | // test not existent data request |
||
237 | array( |
||
238 | "data::blub::request", |
||
239 | array( |
||
240 | "session_id" => md5(time()), |
||
241 | "user" => array( |
||
242 | 'id' => 'foo', |
||
243 | 'displayname' => 'foo', |
||
244 | 'backends' => array ( |
||
245 | 'email' => array ( |
||
246 | 'id' => NULL, |
||
247 | 'displayname' => 'E-mail', |
||
248 | 'protocol' => 'email', |
||
249 | 'namespace' => ' email', |
||
250 | 'value' => array ( |
||
251 | 0 => array ( |
||
252 | ), |
||
253 | ), |
||
254 | ), |
||
255 | 'och' => array ( |
||
256 | 'id' => NULL, |
||
257 | 'displayname' => 'ownCloud Handle', |
||
258 | 'protocol' => 'x-owncloud-handle', |
||
259 | 'namespace' => 'och', |
||
260 | 'value' => 'foo', |
||
261 | ), |
||
262 | ), |
||
263 | 'address_book_id' => 'local', |
||
264 | 'address_book_backend' => '', |
||
265 | ), |
||
266 | ), |
||
267 | array( |
||
268 | "type" => "data::blub::response", |
||
269 | "data" => array( |
||
270 | "status" => "error", |
||
271 | "msg" => ApiController::DATA_ACTION_NOT_FOUND |
||
272 | ) |
||
273 | ) |
||
274 | ), |
||
275 | // test not existent push request |
||
276 | array( |
||
277 | "push::blub::request", |
||
278 | array( |
||
279 | "session_id" => md5(time()), |
||
280 | "user" => array( |
||
281 | 'id' => 'foo', |
||
282 | 'displayname' => 'foo', |
||
283 | 'backends' => array ( |
||
284 | 'email' => array ( |
||
285 | 'id' => NULL, |
||
286 | 'displayname' => 'E-mail', |
||
287 | 'protocol' => 'email', |
||
288 | 'namespace' => ' email', |
||
289 | 'value' => array ( |
||
290 | 0 => array ( |
||
291 | ), |
||
292 | ), |
||
293 | ), |
||
294 | 'och' => array ( |
||
295 | 'id' => NULL, |
||
296 | 'displayname' => 'ownCloud Handle', |
||
297 | 'protocol' => 'x-owncloud-handle', |
||
298 | 'namespace' => 'och', |
||
299 | 'value' => 'foo', |
||
300 | ), |
||
301 | ), |
||
302 | 'address_book_id' => 'local', |
||
303 | 'address_book_backend' => '', |
||
304 | ), |
||
305 | ), |
||
306 | array( |
||
307 | "type" => "push::blub::response", |
||
308 | "data" => array( |
||
309 | "status" => "error", |
||
310 | "msg" => ApiController::PUSH_ACTION_NOT_FOUND |
||
311 | ) |
||
312 | ) |
||
313 | ), |
||
314 | // test user not equal to the logged in OC user |
||
315 | array( |
||
316 | "push::get::request", |
||
317 | array( |
||
318 | "session_id" => md5(time()), |
||
319 | "user" => array( |
||
320 | 'id' => 'bar', |
||
321 | 'displayname' => 'bar', |
||
322 | 'backends' => array ( |
||
323 | 'email' => array ( |
||
324 | 'id' => NULL, |
||
325 | 'displayname' => 'E-mail', |
||
326 | 'protocol' => 'email', |
||
327 | 'namespace' => ' email', |
||
328 | 'value' => array ( |
||
329 | 0 => array ( |
||
330 | ), |
||
331 | ), |
||
332 | ), |
||
333 | 'och' => array ( |
||
334 | 'id' => NULL, |
||
335 | 'displayname' => 'ownCloud Handle', |
||
336 | 'protocol' => 'x-owncloud-handle', |
||
337 | 'namespace' => 'och', |
||
338 | 'value' => 'bar', |
||
339 | ), |
||
340 | ), |
||
341 | 'address_book_id' => 'local', |
||
342 | 'address_book_backend' => '', |
||
343 | ), |
||
344 | ), |
||
345 | array( |
||
346 | "type" => "push::get::response", |
||
347 | "data" => array( |
||
348 | "status" => "error", |
||
349 | "msg" => ApiController::USER_NOT_EQUAL_TO_OC_USER |
||
350 | ) |
||
351 | ) |
||
352 | ), |
||
353 | ); |
||
354 | } |
||
355 | |||
604 | } |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.