| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 36 |
| 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 |
||
| 28 | public function providePaginatorAdapters(): iterable |
||
| 29 | { |
||
| 30 | yield 'empty' => [ |
||
| 31 | [ |
||
| 32 | 'data' => [], |
||
| 33 | 'pagination' => [ |
||
| 34 | 'currentPage' => 1, |
||
| 35 | 'pagesCount' => 0, |
||
| 36 | 'itemsPerPage' => 10, |
||
| 37 | 'itemsInCurrentPage' => 0, |
||
| 38 | 'totalItems' => 0, |
||
| 39 | ], |
||
| 40 | ], |
||
| 41 | new Paginator(new ArrayAdapter([])), |
||
| 42 | ]; |
||
| 43 | |||
| 44 | yield 'with two pages' => [ |
||
| 45 | [ |
||
| 46 | 'data' => [1, 2], |
||
| 47 | 'pagination' => [ |
||
| 48 | 'currentPage' => 1, |
||
| 49 | 'pagesCount' => 2, |
||
| 50 | 'itemsPerPage' => 2, |
||
| 51 | 'itemsInCurrentPage' => 2, |
||
| 52 | 'totalItems' => 3, |
||
| 53 | ], |
||
| 54 | ], |
||
| 55 | (new Paginator(new ArrayAdapter(range(1, 3))))->setItemCountPerPage(2), |
||
| 56 | ]; |
||
| 57 | |||
| 58 | yield 'not in first page' => [ |
||
| 59 | [ |
||
| 60 | 'data' => [7, 8, 9], |
||
| 61 | 'pagination' => [ |
||
| 62 | 'currentPage' => 3, |
||
| 63 | 'pagesCount' => 5, |
||
| 64 | 'itemsPerPage' => 3, |
||
| 65 | 'itemsInCurrentPage' => 3, |
||
| 66 | 'totalItems' => 15, |
||
| 67 | ], |
||
| 68 | ], |
||
| 69 | (new Paginator(new ArrayAdapter(range(1, 15))))->setItemCountPerPage(3)->setCurrentPageNumber(3), |
||
| 70 | ]; |
||
| 71 | |||
| 72 | yield 'last incomplete page' => [ |
||
| 73 | [ |
||
| 74 | 'data' => [13], |
||
| 75 | 'pagination' => [ |
||
| 76 | 'currentPage' => 5, |
||
| 77 | 'pagesCount' => 5, |
||
| 78 | 'itemsPerPage' => 3, |
||
| 79 | 'itemsInCurrentPage' => 1, |
||
| 80 | 'totalItems' => 13, |
||
| 81 | ], |
||
| 82 | ], |
||
| 83 | (new Paginator(new ArrayAdapter(range(1, 13))))->setItemCountPerPage(3)->setCurrentPageNumber(5), |
||
| 84 | ]; |
||
| 129 |