Conditions | 1 |
Paths | 1 |
Total Lines | 611 |
Code Lines | 402 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
37 | public static function valueProvider(): Generator |
||
38 | { |
||
39 | yield 'Ascending forward start inclusive' => [ |
||
40 | function (Table $posts) { |
||
41 | /** @var LampagerBehavior&Table $posts */ |
||
42 | return $posts->lampager() |
||
43 | ->forward() |
||
44 | ->seekable() |
||
45 | ->limit(3) |
||
46 | ->orderByAsc('modified') |
||
47 | ->orderByAsc('id'); |
||
48 | }, |
||
49 | new PaginationResult( |
||
50 | [ |
||
51 | new Entity([ |
||
52 | 'id' => 1, |
||
53 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
54 | ]), |
||
55 | new Entity([ |
||
56 | 'id' => 3, |
||
57 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
58 | ]), |
||
59 | new Entity([ |
||
60 | 'id' => 5, |
||
61 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
62 | ]), |
||
63 | ], |
||
64 | [ |
||
65 | 'hasPrevious' => null, |
||
66 | 'previousCursor' => null, |
||
67 | 'hasNext' => true, |
||
68 | 'nextCursor' => [ |
||
69 | 'id' => 2, |
||
70 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
71 | ], |
||
72 | ] |
||
73 | ), |
||
74 | ]; |
||
75 | |||
76 | yield 'Ascending forward start exclusive' => [ |
||
77 | function (Table $posts) { |
||
78 | /** @var LampagerBehavior&Table $posts */ |
||
79 | return $posts->lampager() |
||
80 | ->forward() |
||
81 | ->seekable() |
||
82 | ->exclusive() |
||
83 | ->limit(3) |
||
84 | ->orderByAsc('modified') |
||
85 | ->orderByAsc('id'); |
||
86 | }, |
||
87 | new PaginationResult( |
||
88 | [ |
||
89 | new Entity([ |
||
90 | 'id' => 1, |
||
91 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
92 | ]), |
||
93 | new Entity([ |
||
94 | 'id' => 3, |
||
95 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
96 | ]), |
||
97 | new Entity([ |
||
98 | 'id' => 5, |
||
99 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
100 | ]), |
||
101 | ], |
||
102 | [ |
||
103 | 'hasPrevious' => null, |
||
104 | 'previousCursor' => null, |
||
105 | 'hasNext' => true, |
||
106 | 'nextCursor' => [ |
||
107 | 'id' => 5, |
||
108 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
109 | ], |
||
110 | ] |
||
111 | ), |
||
112 | ]; |
||
113 | |||
114 | yield 'Ascending forward inclusive' => [ |
||
115 | function (Table $posts) { |
||
116 | /** @var LampagerBehavior&Table $posts */ |
||
117 | return $posts->lampager() |
||
118 | ->forward() |
||
119 | ->seekable() |
||
120 | ->limit(3) |
||
121 | ->orderByAsc('modified') |
||
122 | ->orderByAsc('id') |
||
123 | ->cursor([ |
||
124 | 'id' => 3, |
||
125 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
126 | ]); |
||
127 | }, |
||
128 | new PaginationResult( |
||
129 | [ |
||
130 | new Entity([ |
||
131 | 'id' => 3, |
||
132 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
133 | ]), |
||
134 | new Entity([ |
||
135 | 'id' => 5, |
||
136 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
137 | ]), |
||
138 | new Entity([ |
||
139 | 'id' => 2, |
||
140 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
141 | ]), |
||
142 | ], |
||
143 | [ |
||
144 | 'hasPrevious' => true, |
||
145 | 'previousCursor' => [ |
||
146 | 'id' => 1, |
||
147 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
148 | ], |
||
149 | 'hasNext' => true, |
||
150 | 'nextCursor' => [ |
||
151 | 'id' => 4, |
||
152 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
153 | ], |
||
154 | ] |
||
155 | ), |
||
156 | ]; |
||
157 | |||
158 | yield 'Ascending forward exclusive' => [ |
||
159 | function (Table $posts) { |
||
160 | /** @var LampagerBehavior&Table $posts */ |
||
161 | return $posts->lampager() |
||
162 | ->forward() |
||
163 | ->seekable() |
||
164 | ->exclusive() |
||
165 | ->limit(3) |
||
166 | ->orderByAsc('modified') |
||
167 | ->orderByAsc('id') |
||
168 | ->cursor([ |
||
169 | 'id' => 3, |
||
170 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
171 | ]); |
||
172 | }, |
||
173 | new PaginationResult( |
||
174 | [ |
||
175 | new Entity([ |
||
176 | 'id' => 5, |
||
177 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
178 | ]), |
||
179 | new Entity([ |
||
180 | 'id' => 2, |
||
181 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
182 | ]), |
||
183 | new Entity([ |
||
184 | 'id' => 4, |
||
185 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
186 | ]), |
||
187 | ], |
||
188 | [ |
||
189 | 'hasPrevious' => true, |
||
190 | 'previousCursor' => [ |
||
191 | 'id' => 5, |
||
192 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
193 | ], |
||
194 | 'hasNext' => false, |
||
195 | 'nextCursor' => null, |
||
196 | ] |
||
197 | ), |
||
198 | ]; |
||
199 | |||
200 | yield 'Ascending backward start inclusive' => [ |
||
201 | function (Table $posts) { |
||
202 | /** @var LampagerBehavior&Table $posts */ |
||
203 | return $posts->lampager() |
||
204 | ->backward() |
||
205 | ->seekable() |
||
206 | ->limit(3) |
||
207 | ->orderByAsc('modified') |
||
208 | ->orderByAsc('id'); |
||
209 | }, |
||
210 | new PaginationResult( |
||
211 | [ |
||
212 | new Entity([ |
||
213 | 'id' => 5, |
||
214 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
215 | ]), |
||
216 | new Entity([ |
||
217 | 'id' => 2, |
||
218 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
219 | ]), |
||
220 | new Entity([ |
||
221 | 'id' => 4, |
||
222 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
223 | ]), |
||
224 | ], |
||
225 | [ |
||
226 | 'hasPrevious' => true, |
||
227 | 'previousCursor' => [ |
||
228 | 'id' => 3, |
||
229 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
230 | ], |
||
231 | 'hasNext' => null, |
||
232 | 'nextCursor' => null, |
||
233 | ] |
||
234 | ), |
||
235 | ]; |
||
236 | |||
237 | yield 'Ascending backward start exclusive' => [ |
||
238 | function (Table $posts) { |
||
239 | /** @var LampagerBehavior&Table $posts */ |
||
240 | return $posts->lampager() |
||
241 | ->backward() |
||
242 | ->seekable() |
||
243 | ->exclusive() |
||
244 | ->limit(3) |
||
245 | ->orderByAsc('modified') |
||
246 | ->orderByAsc('id'); |
||
247 | }, |
||
248 | new PaginationResult( |
||
249 | [ |
||
250 | new Entity([ |
||
251 | 'id' => 5, |
||
252 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
253 | ]), |
||
254 | new Entity([ |
||
255 | 'id' => 2, |
||
256 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
257 | ]), |
||
258 | new Entity([ |
||
259 | 'id' => 4, |
||
260 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
261 | ]), |
||
262 | ], |
||
263 | [ |
||
264 | 'hasPrevious' => true, |
||
265 | 'previousCursor' => [ |
||
266 | 'id' => 5, |
||
267 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
268 | ], |
||
269 | 'hasNext' => null, |
||
270 | 'nextCursor' => null, |
||
271 | ] |
||
272 | ), |
||
273 | ]; |
||
274 | |||
275 | yield 'Ascending backward inclusive' => [ |
||
276 | function (Table $posts) { |
||
277 | /** @var LampagerBehavior&Table $posts */ |
||
278 | return $posts->lampager() |
||
279 | ->backward() |
||
280 | ->seekable() |
||
281 | ->limit(3) |
||
282 | ->orderByAsc('modified') |
||
283 | ->orderByAsc('id') |
||
284 | ->cursor([ |
||
285 | 'id' => 3, |
||
286 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
287 | ]); |
||
288 | }, |
||
289 | new PaginationResult( |
||
290 | [ |
||
291 | new Entity([ |
||
292 | 'id' => 1, |
||
293 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
294 | ]), |
||
295 | new Entity([ |
||
296 | 'id' => 3, |
||
297 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
298 | ]), |
||
299 | ], |
||
300 | [ |
||
301 | 'hasPrevious' => false, |
||
302 | 'previousCursor' => null, |
||
303 | 'hasNext' => true, |
||
304 | 'nextCursor' => [ |
||
305 | 'id' => 5, |
||
306 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
307 | ], |
||
308 | ] |
||
309 | ), |
||
310 | ]; |
||
311 | |||
312 | yield 'Ascending backward exclusive' => [ |
||
313 | function (Table $posts) { |
||
314 | /** @var LampagerBehavior&Table $posts */ |
||
315 | return $posts->lampager() |
||
316 | ->backward() |
||
317 | ->seekable() |
||
318 | ->exclusive() |
||
319 | ->limit(3) |
||
320 | ->orderByAsc('modified') |
||
321 | ->orderByAsc('id') |
||
322 | ->cursor([ |
||
323 | 'id' => 3, |
||
324 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
325 | ]); |
||
326 | }, |
||
327 | new PaginationResult( |
||
328 | [ |
||
329 | new Entity([ |
||
330 | 'id' => 1, |
||
331 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
332 | ]), |
||
333 | ], |
||
334 | [ |
||
335 | 'hasPrevious' => false, |
||
336 | 'previousCursor' => null, |
||
337 | 'hasNext' => true, |
||
338 | 'nextCursor' => [ |
||
339 | 'id' => 1, |
||
340 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
341 | ], |
||
342 | ] |
||
343 | ), |
||
344 | ]; |
||
345 | |||
346 | yield 'Descending forward start inclusive' => [ |
||
347 | function (Table $posts) { |
||
348 | /** @var LampagerBehavior&Table $posts */ |
||
349 | return $posts->lampager() |
||
350 | ->forward() |
||
351 | ->seekable() |
||
352 | ->limit(3) |
||
353 | ->orderByDesc('modified') |
||
354 | ->orderByDesc('id'); |
||
355 | }, |
||
356 | new PaginationResult( |
||
357 | [ |
||
358 | new Entity([ |
||
359 | 'id' => 4, |
||
360 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
361 | ]), |
||
362 | new Entity([ |
||
363 | 'id' => 2, |
||
364 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
365 | ]), |
||
366 | new Entity([ |
||
367 | 'id' => 5, |
||
368 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
369 | ]), |
||
370 | ], |
||
371 | [ |
||
372 | 'hasPrevious' => null, |
||
373 | 'previousCursor' => null, |
||
374 | 'hasNext' => true, |
||
375 | 'nextCursor' => [ |
||
376 | 'id' => 3, |
||
377 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
378 | ], |
||
379 | ] |
||
380 | ), |
||
381 | ]; |
||
382 | |||
383 | yield 'Descending forward start exclusive' => [ |
||
384 | function (Table $posts) { |
||
385 | /** @var LampagerBehavior&Table $posts */ |
||
386 | return $posts->lampager() |
||
387 | ->forward() |
||
388 | ->seekable() |
||
389 | ->exclusive() |
||
390 | ->limit(3) |
||
391 | ->orderByDesc('modified') |
||
392 | ->orderByDesc('id'); |
||
393 | }, |
||
394 | new PaginationResult( |
||
395 | [ |
||
396 | new Entity([ |
||
397 | 'id' => 4, |
||
398 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
399 | ]), |
||
400 | new Entity([ |
||
401 | 'id' => 2, |
||
402 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
403 | ]), |
||
404 | new Entity([ |
||
405 | 'id' => 5, |
||
406 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
407 | ]), |
||
408 | ], |
||
409 | [ |
||
410 | 'hasPrevious' => null, |
||
411 | 'previousCursor' => null, |
||
412 | 'hasNext' => true, |
||
413 | 'nextCursor' => [ |
||
414 | 'id' => 5, |
||
415 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
416 | ], |
||
417 | ] |
||
418 | ), |
||
419 | ]; |
||
420 | |||
421 | yield 'Descending forward inclusive' => [ |
||
422 | function (Table $posts) { |
||
423 | /** @var LampagerBehavior&Table $posts */ |
||
424 | return $posts->lampager() |
||
425 | ->forward() |
||
426 | ->seekable() |
||
427 | ->limit(3) |
||
428 | ->orderByDesc('modified') |
||
429 | ->orderByDesc('id') |
||
430 | ->cursor([ |
||
431 | 'id' => 3, |
||
432 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
433 | ]); |
||
434 | }, |
||
435 | new PaginationResult( |
||
436 | [ |
||
437 | new Entity([ |
||
438 | 'id' => 3, |
||
439 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
440 | ]), |
||
441 | new Entity([ |
||
442 | 'id' => 1, |
||
443 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
444 | ]), |
||
445 | ], |
||
446 | [ |
||
447 | 'hasPrevious' => true, |
||
448 | 'previousCursor' => [ |
||
449 | 'id' => 5, |
||
450 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
451 | ], |
||
452 | 'hasNext' => false, |
||
453 | 'nextCursor' => null, |
||
454 | ] |
||
455 | ), |
||
456 | ]; |
||
457 | |||
458 | yield 'Descending forward exclusive' => [ |
||
459 | function (Table $posts) { |
||
460 | /** @var LampagerBehavior&Table $posts */ |
||
461 | return $posts->lampager() |
||
462 | ->forward() |
||
463 | ->seekable() |
||
464 | ->exclusive() |
||
465 | ->limit(3) |
||
466 | ->orderByDesc('modified') |
||
467 | ->orderByDesc('id') |
||
468 | ->cursor([ |
||
469 | 'id' => 3, |
||
470 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
471 | ]); |
||
472 | }, |
||
473 | new PaginationResult( |
||
474 | [ |
||
475 | new Entity([ |
||
476 | 'id' => 1, |
||
477 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
478 | ]), |
||
479 | ], |
||
480 | [ |
||
481 | 'hasPrevious' => true, |
||
482 | 'previousCursor' => [ |
||
483 | 'id' => 1, |
||
484 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
485 | ], |
||
486 | 'hasNext' => false, |
||
487 | 'nextCursor' => null, |
||
488 | ] |
||
489 | ), |
||
490 | ]; |
||
491 | |||
492 | yield 'Descending backward start inclusive' => [ |
||
493 | function (Table $posts) { |
||
494 | /** @var LampagerBehavior&Table $posts */ |
||
495 | return $posts->lampager() |
||
496 | ->backward() |
||
497 | ->seekable() |
||
498 | ->limit(3) |
||
499 | ->orderByDesc('modified') |
||
500 | ->orderByDesc('id'); |
||
501 | }, |
||
502 | new PaginationResult( |
||
503 | [ |
||
504 | new Entity([ |
||
505 | 'id' => 5, |
||
506 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
507 | ]), |
||
508 | new Entity([ |
||
509 | 'id' => 3, |
||
510 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
511 | ]), |
||
512 | new Entity([ |
||
513 | 'id' => 1, |
||
514 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
515 | ]), |
||
516 | ], |
||
517 | [ |
||
518 | 'hasPrevious' => true, |
||
519 | 'previousCursor' => [ |
||
520 | 'id' => 2, |
||
521 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
522 | ], |
||
523 | 'hasNext' => null, |
||
524 | 'nextCursor' => null, |
||
525 | ] |
||
526 | ), |
||
527 | ]; |
||
528 | |||
529 | yield 'Descending backward start exclusive' => [ |
||
530 | function (Table $posts) { |
||
531 | /** @var LampagerBehavior&Table $posts */ |
||
532 | return $posts->lampager() |
||
533 | ->backward() |
||
534 | ->seekable() |
||
535 | ->exclusive() |
||
536 | ->limit(3) |
||
537 | ->orderByDesc('modified') |
||
538 | ->orderByDesc('id'); |
||
539 | }, |
||
540 | new PaginationResult( |
||
541 | [ |
||
542 | new Entity([ |
||
543 | 'id' => 5, |
||
544 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
545 | ]), |
||
546 | new Entity([ |
||
547 | 'id' => 3, |
||
548 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
549 | ]), |
||
550 | new Entity([ |
||
551 | 'id' => 1, |
||
552 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
553 | ]), |
||
554 | ], |
||
555 | [ |
||
556 | 'hasPrevious' => true, |
||
557 | 'previousCursor' => [ |
||
558 | 'id' => 5, |
||
559 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
560 | ], |
||
561 | 'hasNext' => null, |
||
562 | 'nextCursor' => null, |
||
563 | ] |
||
564 | ), |
||
565 | ]; |
||
566 | |||
567 | yield 'Descending backward inclusive' => [ |
||
568 | function (Table $posts) { |
||
569 | /** @var LampagerBehavior&Table $posts */ |
||
570 | return $posts->lampager() |
||
571 | ->backward() |
||
572 | ->seekable() |
||
573 | ->limit(3) |
||
574 | ->orderByDesc('modified') |
||
575 | ->orderByDesc('id') |
||
576 | ->cursor([ |
||
577 | 'id' => 3, |
||
578 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
579 | ]); |
||
580 | }, |
||
581 | new PaginationResult( |
||
582 | [ |
||
583 | new Entity([ |
||
584 | 'id' => 2, |
||
585 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
586 | ]), |
||
587 | new Entity([ |
||
588 | 'id' => 5, |
||
589 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
590 | ]), |
||
591 | new Entity([ |
||
592 | 'id' => 3, |
||
593 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
594 | ]), |
||
595 | ], |
||
596 | [ |
||
597 | 'hasPrevious' => true, |
||
598 | 'previousCursor' => [ |
||
599 | 'id' => 4, |
||
600 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
601 | ], |
||
602 | 'hasNext' => true, |
||
603 | 'nextCursor' => [ |
||
604 | 'id' => 1, |
||
605 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
606 | ], |
||
607 | ] |
||
608 | ), |
||
609 | ]; |
||
610 | |||
611 | yield 'Descending backward exclusive' => [ |
||
612 | function (Table $posts) { |
||
613 | /** @var LampagerBehavior&Table $posts */ |
||
614 | return $posts->lampager() |
||
615 | ->backward() |
||
616 | ->seekable() |
||
617 | ->exclusive() |
||
618 | ->limit(3) |
||
619 | ->orderByDesc('modified') |
||
620 | ->orderByDesc('id') |
||
621 | ->cursor([ |
||
622 | 'id' => 3, |
||
623 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
624 | ]); |
||
625 | }, |
||
626 | new PaginationResult( |
||
627 | [ |
||
628 | new Entity([ |
||
629 | 'id' => 4, |
||
630 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
631 | ]), |
||
632 | new Entity([ |
||
633 | 'id' => 2, |
||
634 | 'modified' => new DateTime('2017-01-01 11:00:00'), |
||
635 | ]), |
||
636 | new Entity([ |
||
637 | 'id' => 5, |
||
638 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
639 | ]), |
||
640 | ], |
||
641 | [ |
||
642 | 'hasPrevious' => false, |
||
643 | 'previousCursor' => null, |
||
644 | 'hasNext' => true, |
||
645 | 'nextCursor' => [ |
||
646 | 'id' => 5, |
||
647 | 'modified' => new DateTime('2017-01-01 10:00:00'), |
||
648 | ], |
||
1233 |