Conditions | 1 |
Paths | 1 |
Total Lines | 177 |
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 |
||
204 | public function provideCoalesceChanges() { |
||
205 | $id = 0; |
||
206 | |||
207 | // create with a label and site link set |
||
208 | $create11 = $this->makeChange( [ |
||
209 | 'id' => ++$id, |
||
210 | 'type' => 'wikibase-item~add', |
||
211 | 'time' => '20130101010101', |
||
212 | 'object_id' => 'Q1', |
||
213 | 'revision_id' => 1111, |
||
214 | 'user_id' => 1, |
||
215 | ] ); |
||
216 | |||
217 | // set a label |
||
218 | $update11 = $this->makeChange( [ |
||
219 | 'id' => ++$id, |
||
220 | 'type' => 'wikibase-item~update', |
||
221 | 'time' => '20130102020202', |
||
222 | 'object_id' => 'Q1', |
||
223 | 'revision_id' => 1112, |
||
224 | 'user_id' => 1, |
||
225 | 'parent_id' => 1111, |
||
226 | ] ); |
||
227 | |||
228 | // set another label |
||
229 | $anotherUpdate11 = $this->makeChange( [ |
||
230 | 'id' => ++$id, |
||
231 | 'type' => 'wikibase-item~update', |
||
232 | 'time' => '20130102020203', |
||
233 | 'object_id' => 'Q1', |
||
234 | 'revision_id' => 1113, |
||
235 | 'user_id' => 1, |
||
236 | 'parent_id' => 1112, |
||
237 | ] ); |
||
238 | |||
239 | // set another label, by another user |
||
240 | $anotherUpdate21 = $this->makeChange( [ |
||
241 | 'id' => ++$id, |
||
242 | 'type' => 'wikibase-item~update', |
||
243 | 'time' => '20130102020203', |
||
244 | 'object_id' => 'Q1', |
||
245 | 'revision_id' => 1113, |
||
246 | 'user_id' => 2, |
||
247 | 'parent_id' => 1112, |
||
248 | ] ); |
||
249 | |||
250 | // change link to other wiki |
||
251 | $update11XLink = $this->makeChange( [ |
||
252 | 'id' => ++$id, |
||
253 | 'type' => 'wikibase-item~update', |
||
254 | 'time' => '20130101020304', |
||
255 | 'object_id' => 'Q1', |
||
256 | 'revision_id' => 1114, |
||
257 | 'user_id' => 1, |
||
258 | 'parent_id' => 1113, |
||
259 | ] ); |
||
260 | |||
261 | // change link to other wiki |
||
262 | $update11Badge = $this->makeChange( [ |
||
263 | 'id' => ++$id, |
||
264 | 'type' => 'wikibase-item~update', |
||
265 | 'time' => '20130101020305', |
||
266 | 'object_id' => 'Q1', |
||
267 | 'revision_id' => 1115, |
||
268 | 'user_id' => 1, |
||
269 | 'parent_id' => 1114, |
||
270 | ] ); |
||
271 | |||
272 | // change link to local wiki |
||
273 | $update11Link = $this->makeChange( [ |
||
274 | 'id' => ++$id, |
||
275 | 'type' => 'wikibase-item~update', |
||
276 | 'time' => '20130102030407', |
||
277 | 'object_id' => 'Q1', |
||
278 | 'revision_id' => 1117, |
||
279 | 'user_id' => 1, |
||
280 | 'parent_id' => 1115, |
||
281 | ] ); |
||
282 | |||
283 | // delete |
||
284 | $delete11 = $this->makeChange( [ |
||
285 | 'id' => ++$id, |
||
286 | 'type' => 'wikibase-item~remove', |
||
287 | 'time' => '20130102030409', |
||
288 | 'object_id' => 'Q1', |
||
289 | 'revision_id' => 0, |
||
290 | 'user_id' => 1, |
||
291 | 'parent_id' => 1118, |
||
292 | ] ); |
||
293 | |||
294 | // set a label |
||
295 | $update12 = $this->makeChange( [ |
||
296 | 'id' => ++$id, |
||
297 | 'type' => 'wikibase-item~update', |
||
298 | 'time' => '20130102020102', |
||
299 | 'object_id' => 'Q2', |
||
300 | 'revision_id' => 1212, |
||
301 | 'user_id' => 1, |
||
302 | 'parent_id' => 1211, |
||
303 | ] ); |
||
304 | |||
305 | // set another label |
||
306 | $anotherUpdate12 = $this->makeChange( [ |
||
307 | 'id' => ++$id, |
||
308 | 'type' => 'wikibase-item~update', |
||
309 | 'time' => '20130102020303', |
||
310 | 'object_id' => 'Q2', |
||
311 | 'revision_id' => 1213, |
||
312 | 'user_id' => 1, |
||
313 | 'parent_id' => 1213, |
||
314 | ] ); |
||
315 | |||
316 | return [ |
||
317 | 'empty' => [ |
||
318 | [], // $changes |
||
319 | [], // $expected |
||
320 | ], |
||
321 | |||
322 | 'single' => [ |
||
323 | [ $create11 ], // $changes |
||
324 | [ $create11 ], // $expected |
||
325 | ], |
||
326 | |||
327 | 'simple run' => [ |
||
328 | [ $update11, $anotherUpdate11 ], // $changes |
||
329 | [ $this->combineChanges( $update11, $anotherUpdate11 ) ], // $expected |
||
330 | ], |
||
331 | |||
332 | 'long run' => [ // create counts as update, delete doesn't |
||
333 | [ $create11, $update11, $anotherUpdate11 ], // $changes |
||
334 | [ $this->combineChanges( $create11, $anotherUpdate11 ) ], // $expected |
||
335 | ], |
||
336 | |||
337 | 'different items' => [ |
||
338 | [ $update11, $anotherUpdate12 ], // $changes |
||
339 | [ $update11, $anotherUpdate12 ], // $changes |
||
340 | ], |
||
341 | |||
342 | 'different users' => [ |
||
343 | [ $update11, $anotherUpdate21 ], // $changes |
||
344 | [ $update11, $anotherUpdate21 ], // $changes |
||
345 | ], |
||
346 | |||
347 | 'reversed' => [ // result is sorted by timestamp |
||
348 | [ $update12, $create11 ], // $changes |
||
349 | [ $create11, $update12 ], // $expected |
||
350 | ], |
||
351 | |||
352 | 'mingled' => [ |
||
353 | [ $update12, $update11, $anotherUpdate11, $anotherUpdate12 ], // $changes |
||
354 | [ // result is sorted by timestamp |
||
355 | $this->combineChanges( $update11, $anotherUpdate11 ), |
||
356 | $this->combineChanges( $update12, $anotherUpdate12 ), |
||
357 | ], // $expected |
||
358 | ], |
||
359 | |||
360 | 'different action' => [ // create counts as update, delete doesn't |
||
361 | [ $update11, $delete11 ], // $changes |
||
362 | [ $update11, $delete11 ], // $expected |
||
363 | ], |
||
364 | |||
365 | 'local link breaks' => [ |
||
366 | [ $update11, $update11Link ], // $changes |
||
367 | [ $update11, $update11Link ], // $expected |
||
368 | ], |
||
369 | |||
370 | 'local link badge change' => [ |
||
371 | [ $update11, $update11Badge ], // $changes |
||
372 | [ $this->combineChanges( $update11, $update11Badge ) ], // $expected |
||
373 | ], |
||
374 | |||
375 | 'other link merges' => [ |
||
376 | [ $update11, $update11XLink ], // $changes |
||
377 | [ $this->combineChanges( $update11, $update11XLink ) ], // $expected |
||
378 | ], |
||
379 | ]; |
||
380 | } |
||
381 | |||
411 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.