Conditions | 10 |
Paths | 73 |
Total Lines | 44 |
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 |
||
13 | protected function renderPageButtons() |
||
14 | { |
||
15 | $pageCount = $this->pagination->getPageCount(); |
||
16 | if ($pageCount < 2 && $this->hideOnSinglePage) { |
||
17 | return ''; |
||
18 | } |
||
19 | |||
20 | $buttons = []; |
||
21 | $currentPage = $this->pagination->getPage(); |
||
22 | |||
23 | // first page |
||
24 | if ($this->firstPageLabel !== false) { |
||
25 | $buttons[] = $this->renderPageButton($this->firstPageLabel, 0, $this->firstPageCssClass, $currentPage <= 0, false); |
||
|
|||
26 | } |
||
27 | |||
28 | // prev page |
||
29 | if ($this->prevPageLabel !== false) { |
||
30 | if (($page = $currentPage - 1) < 0) { |
||
31 | $page = 0; |
||
32 | } |
||
33 | $buttons[] = $this->renderPageButton($this->prevPageLabel, $page, $this->prevPageCssClass, $currentPage <= 0, false, 'prev'); |
||
34 | } |
||
35 | |||
36 | // internal pages |
||
37 | list($beginPage, $endPage) = $this->getPageRange(); |
||
38 | for ($i = $beginPage; $i <= $endPage; ++$i) { |
||
39 | $buttons[] = $this->renderPageButton($i + 1, $i, null, false, $i == $currentPage); |
||
40 | } |
||
41 | |||
42 | // next page |
||
43 | if ($this->nextPageLabel !== false) { |
||
44 | if (($page = $currentPage + 1) >= $pageCount - 1) { |
||
45 | $page = $pageCount - 1; |
||
46 | } |
||
47 | $buttons[] = $this->renderPageButton($this->nextPageLabel, $page, $this->nextPageCssClass, $currentPage >= $pageCount - 1, false, 'next'); |
||
48 | } |
||
49 | |||
50 | // last page |
||
51 | if ($this->lastPageLabel !== false) { |
||
52 | $buttons[] = $this->renderPageButton($this->lastPageLabel, $pageCount - 1, $this->lastPageCssClass, $currentPage >= $pageCount - 1, false); |
||
53 | } |
||
54 | |||
55 | return Html::tag('ul', implode("\n", $buttons), $this->options); |
||
56 | } |
||
57 | |||
89 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.