| Conditions | 19 |
| Paths | 833 |
| Total Lines | 88 |
| Code Lines | 42 |
| 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 |
||
| 83 | public function show() |
||
| 84 | { |
||
| 85 | if (0 == $this->totalRows) |
||
| 86 | { |
||
| 87 | return ''; |
||
| 88 | } |
||
| 89 | |||
| 90 | /* 生成URL */ |
||
| 91 | $this->parameter[$this->p] = '[PAGE]'; |
||
| 92 | $this->url = Route::getSoul()->url(URI . '?' . http_build_query($this->parameter)); |
||
| 93 | /* 计算分页信息 */ |
||
| 94 | $this->totalPages = ceil($this->totalRows / $this->listRows); //总页数 |
||
| 95 | if (!empty($this->totalPages) && $this->nowPage > $this->totalPages) |
||
| 96 | { |
||
| 97 | $this->nowPage = $this->totalPages; |
||
| 98 | } |
||
| 99 | |||
| 100 | /* 计算分页临时变量 */ |
||
| 101 | $now_cool_page = $this->rollPage / 2; |
||
| 102 | $now_cool_page_ceil = ceil($now_cool_page); |
||
| 103 | $this->lastSuffix && $this->config['last'] = $this->totalPages; |
||
| 104 | |||
| 105 | //上一页 |
||
| 106 | $up_row = $this->nowPage - 1; |
||
| 107 | $up_page = $up_row > 0 ? '<a class="prev" href="' . $this->url($up_row) . '">' . $this->config['prev'] . '</a>' : ''; |
||
| 108 | |||
| 109 | //下一页 |
||
| 110 | $down_row = $this->nowPage + 1; |
||
| 111 | $down_page = ($down_row <= $this->totalPages) ? '<a class="next" href="' . $this->url($down_row) . '">' . $this->config['next'] . '</a>' : ''; |
||
| 112 | |||
| 113 | //第一页 |
||
| 114 | $the_first = ''; |
||
| 115 | if ($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1) |
||
| 116 | { |
||
| 117 | $the_first = '<a class="first" href="' . $this->url(1) . '">' . $this->config['first'] . '</a>'; |
||
| 118 | } |
||
| 119 | |||
| 120 | //最后一页 |
||
| 121 | $the_end = ''; |
||
| 122 | if ($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages) |
||
| 123 | { |
||
| 124 | $the_end = '<a class="end" href="' . $this->url($this->totalPages) . '">' . $this->config['last'] . '</a>'; |
||
| 125 | } |
||
| 126 | |||
| 127 | //数字连接 |
||
| 128 | $link_page = ""; |
||
| 129 | for ($i = 1; $i <= $this->rollPage; $i++) |
||
| 130 | { |
||
| 131 | if (($this->nowPage - $now_cool_page) <= 0) |
||
| 132 | { |
||
| 133 | $page = $i; |
||
| 134 | } |
||
| 135 | elseif (($this->nowPage + $now_cool_page - 1) >= $this->totalPages) |
||
| 136 | { |
||
| 137 | $page = $this->totalPages - $this->rollPage + $i; |
||
| 138 | } |
||
| 139 | else |
||
| 140 | { |
||
| 141 | $page = $this->nowPage - $now_cool_page_ceil + $i; |
||
| 142 | } |
||
| 143 | if ($page > 0 && $page != $this->nowPage) |
||
| 144 | { |
||
| 145 | |||
| 146 | if ($page <= $this->totalPages) |
||
| 147 | { |
||
| 148 | $link_page .= '<a class="num" href="' . $this->url($page) . '">' . $page . '</a>'; |
||
| 149 | } |
||
| 150 | else |
||
| 151 | { |
||
| 152 | break; |
||
| 153 | } |
||
| 154 | } |
||
| 155 | else |
||
| 156 | { |
||
| 157 | if ($page > 0 && $this->totalPages != 1) |
||
| 158 | { |
||
| 159 | $link_page .= '<span class="current">' . $page . '</span>'; |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | //替换分页内容 |
||
| 165 | $page_str = str_replace( |
||
| 166 | array('%HEADER%', '%NOW_PAGE%', '%UP_PAGE%', '%DOWN_PAGE%', '%FIRST%', '%LINK_PAGE%', '%END%', '%TOTAL_ROW%', '%TOTAL_PAGE%'), |
||
| 167 | array($this->config['header'], $this->nowPage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages), |
||
| 168 | $this->config['theme']); |
||
| 169 | return "<div>{$page_str}</div>"; |
||
| 170 | } |
||
| 171 | } |
||
| 172 |