Conditions | 9 |
Paths | 6 |
Total Lines | 84 |
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 |
||
95 | public function display_stats() |
||
96 | { |
||
97 | // Count number of categories |
||
98 | $sql = 'SELECT COUNT(cat_id) AS nb_cats |
||
99 | FROM ' . $this->categories_table; |
||
100 | $result = $this->db->sql_query($sql); |
||
101 | $total_cats = (int) $this->db->sql_fetchfield('nb_cats'); |
||
102 | $this->db->sql_freeresult($result); |
||
103 | |||
104 | // Cont number of links |
||
105 | $sql = 'SELECT link_id, link_active |
||
106 | FROM ' . $this->links_table; |
||
107 | $result = $this->db->sql_query($sql); |
||
108 | $total_links = $waiting_links = 0; |
||
109 | while ($row = $this->db->sql_fetchrow($result)) |
||
110 | { |
||
111 | $total_links++; |
||
112 | |||
113 | if (!$row['link_active']) |
||
114 | { |
||
115 | $waiting_links++; |
||
116 | } |
||
117 | } |
||
118 | $this->db->sql_freeresult($result); |
||
119 | |||
120 | // Comments number calculating |
||
121 | $sql = 'SELECT COUNT(comment_id) AS nb_comments |
||
122 | FROM ' . $this->comments_table; |
||
123 | $result = $this->db->sql_query($sql); |
||
124 | $total_comments = (int) $this->db->sql_fetchfield('nb_comments'); |
||
125 | $this->db->sql_freeresult($result); |
||
126 | |||
127 | // Votes number calculating |
||
128 | $sql = 'SELECT COUNT(vote_id) AS nb_votes |
||
129 | FROM ' . $this->votes_table; |
||
130 | $result = $this->db->sql_query($sql); |
||
131 | $total_votes = (int) $this->db->sql_fetchfield('nb_votes'); |
||
132 | $this->db->sql_freeresult($result); |
||
133 | |||
134 | // Click number calculating |
||
135 | $sql = 'SELECT SUM(link_view) AS nb_clicks |
||
136 | FROM ' . $this->links_table; |
||
137 | $result = $this->db->sql_query($sql); |
||
138 | $total_clicks = (int) $this->db->sql_fetchfield('nb_clicks'); |
||
139 | $this->db->sql_freeresult($result); |
||
140 | |||
141 | $banners_dir_size = 0; |
||
142 | |||
143 | $banners_path = $this->get_banner_path(); |
||
144 | |||
145 | if ($banners_dir = @opendir($banners_path)) |
||
146 | { |
||
147 | while (($file = readdir($banners_dir)) !== false) |
||
148 | { |
||
149 | if ($file[0] != '.' && $file[0] != '..' && strpos($file, 'index.') === false && strpos($file, '.db') === false) |
||
150 | { |
||
151 | $banners_dir_size += filesize($banners_path . $file); |
||
152 | } |
||
153 | } |
||
154 | closedir($banners_dir); |
||
155 | |||
156 | $banners_dir_size = get_formatted_filesize($banners_dir_size); |
||
157 | } |
||
158 | else |
||
159 | { |
||
160 | // Couldn't open banners dir. |
||
161 | $banners_dir_size = $this->language->lang('NOT_AVAILABLE'); |
||
162 | } |
||
163 | |||
164 | $total_orphan = $this->_orphan_files(); |
||
165 | |||
166 | $this->template->assign_vars(array( |
||
167 | 'U_ACTION' => $this->u_action, |
||
168 | |||
169 | 'TOTAL_CATS' => $total_cats, |
||
170 | 'TOTAL_LINKS' => $total_links-$waiting_links, |
||
171 | 'WAITING_LINKS' => $waiting_links, |
||
172 | 'TOTAL_COMMENTS' => $total_comments, |
||
173 | 'TOTAL_VOTES' => $total_votes, |
||
174 | 'TOTAL_CLICKS' => $total_clicks, |
||
175 | 'TOTAL_ORPHANS' => $total_orphan, |
||
176 | 'BANNERS_DIR_SIZE' => $banners_dir_size, |
||
177 | )); |
||
178 | } |
||
179 | |||
323 |