Conditions | 11 |
Paths | 512 |
Total Lines | 126 |
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 |
||
135 | $data['page_size'] = $list['file_size']; |
||
136 | $data['page_biggest'] = $list['file_max']; |
||
137 | $data['page_smallest'] = $list['file_min']; |
||
138 | $data['page_nscount'] = $list['dir_count']; |
||
139 | $data['page_nsnest'] = $list['dir_nest']; |
||
140 | if ($list['file_count']) $data['page_avg'] = $list['file_size'] / $list['file_count']; |
||
141 | $data['page_oldest'] = $list['file_oldest']; |
||
142 | unset($list); |
||
143 | |||
144 | // number and size of media |
||
145 | $list = array(); |
||
146 | search($list, $conf['mediadir'], array($this, 'searchCountCallback'), array('all'=>true)); |
||
147 | $data['media_count'] = $list['file_count']; |
||
148 | $data['media_size'] = $list['file_size']; |
||
149 | $data['media_biggest'] = $list['file_max']; |
||
150 | $data['media_smallest'] = $list['file_min']; |
||
151 | $data['media_nscount'] = $list['dir_count']; |
||
152 | $data['media_nsnest'] = $list['dir_nest']; |
||
153 | if ($list['file_count']) $data['media_avg'] = $list['file_size'] / $list['file_count']; |
||
154 | unset($list); |
||
155 | |||
156 | // number and size of cache |
||
157 | $list = array(); |
||
158 | search($list, $conf['cachedir'], array($this, 'searchCountCallback'), array('all'=>true)); |
||
159 | $data['cache_count'] = $list['file_count']; |
||
160 | $data['cache_size'] = $list['file_size']; |
||
161 | $data['cache_biggest'] = $list['file_max']; |
||
162 | $data['cache_smallest'] = $list['file_min']; |
||
163 | if ($list['file_count']) $data['cache_avg'] = $list['file_size'] / $list['file_count']; |
||
164 | unset($list); |
||
165 | |||
166 | // number and size of index |
||
167 | $list = array(); |
||
168 | search($list, $conf['indexdir'], array($this, 'searchCountCallback'), array('all'=>true)); |
||
169 | $data['index_count'] = $list['file_count']; |
||
170 | $data['index_size'] = $list['file_size']; |
||
171 | $data['index_biggest'] = $list['file_max']; |
||
172 | $data['index_smallest'] = $list['file_min']; |
||
173 | if ($list['file_count']) $data['index_avg'] = $list['file_size'] / $list['file_count']; |
||
174 | unset($list); |
||
175 | |||
176 | // number and size of meta |
||
177 | $list = array(); |
||
178 | search($list, $conf['metadir'], array($this, 'searchCountCallback'), array('all'=>true)); |
||
179 | $data['meta_count'] = $list['file_count']; |
||
180 | $data['meta_size'] = $list['file_size']; |
||
181 | $data['meta_biggest'] = $list['file_max']; |
||
182 | $data['meta_smallest'] = $list['file_min']; |
||
183 | if ($list['file_count']) $data['meta_avg'] = $list['file_size'] / $list['file_count']; |
||
184 | unset($list); |
||
185 | |||
186 | // number and size of attic |
||
187 | $list = array(); |
||
188 | search($list, $conf['olddir'], array($this, 'searchCountCallback'), array('all'=>true)); |
||
189 | $data['attic_count'] = $list['file_count']; |
||
190 | $data['attic_size'] = $list['file_size']; |
||
191 | $data['attic_biggest'] = $list['file_max']; |
||
192 | $data['attic_smallest'] = $list['file_min']; |
||
193 | if ($list['file_count']) $data['attic_avg'] = $list['file_size'] / $list['file_count']; |
||
194 | $data['attic_oldest'] = $list['file_oldest']; |
||
195 | unset($list); |
||
196 | |||
197 | // user count |
||
198 | if ($auth && $auth->canDo('getUserCount')) { |
||
199 | $data['user_count'] = $auth->getUserCount(); |
||
200 | } |
||
201 | |||
202 | // calculate edits per day |
||
203 | $list = @file($conf['metadir'].'/_dokuwiki.changes'); |
||
204 | $count = count($list); |
||
205 | if ($count > 2) { |
||
206 | $first = (int) substr(array_shift($list), 0, 10); |
||
207 | $last = (int) substr(array_pop($list), 0, 10); |
||
208 | $dur = ($last - $first)/(60*60*24); // number of days in the changelog |
||
209 | $data['edits_per_day'] = $count/$dur; |
||
210 | } |
||
211 | unset($list); |
||
212 | |||
213 | // plugins |
||
214 | $data['plugin'] = plugin_list(); |
||
215 | |||
216 | // pcre info |
||
217 | if (defined('PCRE_VERSION')) $data['pcre_version'] = PCRE_VERSION; |
||
218 | $data['pcre_backtrack'] = ini_get('pcre.backtrack_limit'); |
||
219 | $data['pcre_recursion'] = ini_get('pcre.recursion_limit'); |
||
220 | |||
221 | // php info |
||
222 | $data['os'] = PHP_OS; |
||
223 | $data['webserver'] = $_SERVER['SERVER_SOFTWARE']; |
||
224 | $data['php_version'] = phpversion(); |
||
225 | $data['php_sapi'] = php_sapi_name(); |
||
226 | $data['php_memory'] = php_to_byte(ini_get('memory_limit')); |
||
227 | $data['php_exectime'] = $phptime; |
||
228 | $data['php_extension'] = get_loaded_extensions(); |
||
229 | |||
230 | // plugin usage data |
||
231 | $this->addPluginUsageData($data); |
||
232 | |||
233 | return $data; |
||
234 | } |
||
235 | |||
236 | /** |
||
237 | * Triggers event to let plugins add their own data |
||
238 | * |
||
239 | * @param $data |
||
240 | */ |
||
241 | protected function addPluginUsageData(&$data) |
||
242 | { |
||
243 | $pluginsData = array(); |
||
244 | trigger_event('PLUGIN_POPULARITY_DATA_SETUP', $pluginsData); |
||
245 | foreach ($pluginsData as $plugin => $d) { |
||
246 | if (is_array($d)) { |
||
247 | foreach ($d as $key => $value) { |
||
248 | $data['plugin_' . $plugin . '_' . $key] = $value; |
||
249 | } |
||
250 | } else { |
||
251 | $data['plugin_' . $plugin] = $d; |
||
252 | } |
||
253 | } |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * Callback to search and count the content of directories in DokuWiki |
||
258 | * |
||
259 | * @param array &$data Reference to the result data structure |
||
260 | * @param string $base Base usually $conf['datadir'] |
||
261 | * @param string $file current file or directory relative to $base |
||
290 |