Conditions | 14 |
Paths | 288 |
Total Lines | 76 |
Code Lines | 48 |
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 |
||
34 | public function render() |
||
|
|||
35 | { |
||
36 | $total = $this->total; |
||
37 | |||
38 | if ($this->page < 1) { |
||
39 | $page = 1; |
||
40 | } else { |
||
41 | $page = $this->page; |
||
42 | } |
||
43 | |||
44 | if (!(int) $this->limit) { |
||
45 | $limit = 10; |
||
46 | } else { |
||
47 | $limit = $this->limit; |
||
48 | } |
||
49 | |||
50 | $num_links = $this->num_links; |
||
51 | $num_pages = ceil($total / $limit); |
||
52 | |||
53 | $this->url = str_replace('%7Bpage%7D', '{page}', $this->url); |
||
54 | |||
55 | $output = '<ul class="uk-pagination uk-flex-center uk-padding-small uk-padding-remove-bottom">'; |
||
56 | |||
57 | if ($page > 1) { |
||
58 | $output .= '<li><a href="' . str_replace(array('&page={page}', '&page={page}', '?page={page}'), '', $this->url) . '">' . $this->text_first . '</a></li>'; |
||
59 | |||
60 | if ($page - 1 === 1) { |
||
61 | $output .= '<li><a href="' . str_replace(array('&page={page}', '&page={page}', '?page={page}'), '', $this->url) . '"><span uk-pagination-previous></span></a></li>'; |
||
62 | } else { |
||
63 | $output .= '<li><a href="' . str_replace('{page}', $page - 1, $this->url) . '"><span uk-pagination-previous></span></a></li>'; |
||
64 | } |
||
65 | } |
||
66 | |||
67 | if ($num_pages > 1) { |
||
68 | if ($num_pages <= $num_links) { |
||
69 | $start = 1; |
||
70 | $end = $num_pages; |
||
71 | } else { |
||
72 | $start = $page - floor($num_links / 2); |
||
73 | $end = $page + floor($num_links / 2); |
||
74 | |||
75 | if ($start < 1) { |
||
76 | $end += abs($start) + 1; |
||
77 | $start = 1; |
||
78 | } |
||
79 | |||
80 | if ($end > $num_pages) { |
||
81 | $start -= ($end - $num_pages); |
||
82 | $end = $num_pages; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | for ($i = $start; $i <= $end; $i++) { |
||
87 | if ($page == $i) { |
||
88 | $output .= '<li class="uk-active"><span>' . $i . '</span></li>'; |
||
89 | } else { |
||
90 | if ($i === 1) { |
||
91 | $output .= '<li><a href="' . str_replace(array('&page={page}', '&page={page}', '?page={page}'), '', $this->url) . '">' . $i . '</a></li>'; |
||
92 | } else { |
||
93 | $output .= '<li><a href="' . str_replace('{page}', $i, $this->url) . '">' . $i . '</a></li>'; |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | if ($page < $num_pages) { |
||
100 | $output .= '<li><a href="' . str_replace('{page}', $page + 1, $this->url) . '"><span uk-pagination-next></span></a></li>'; |
||
101 | $output .= '<li><a href="' . str_replace('{page}', $num_pages, $this->url) . '">' . $this->text_last . '</a></li>'; |
||
102 | } |
||
103 | |||
104 | $output .= '</ul>'; |
||
105 | |||
106 | if ($num_pages > 1) { |
||
107 | return $output; |
||
108 | } else { |
||
109 | return ''; |
||
110 | } |
||
113 |