| 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 | $list = array();  | 
            ||
| 136 |         search($list, $conf['datadir'], array($this, 'searchCountCallback'), array('all'=>false), ''); | 
            ||
| 137 | $data['page_count'] = $list['file_count'];  | 
            ||
| 138 | $data['page_size'] = $list['file_size'];  | 
            ||
| 139 | $data['page_biggest'] = $list['file_max'];  | 
            ||
| 140 | $data['page_smallest'] = $list['file_min'];  | 
            ||
| 141 | $data['page_nscount'] = $list['dir_count'];  | 
            ||
| 142 | $data['page_nsnest'] = $list['dir_nest'];  | 
            ||
| 143 | if ($list['file_count']) $data['page_avg'] = $list['file_size'] / $list['file_count'];  | 
            ||
| 144 | $data['page_oldest'] = $list['file_oldest'];  | 
            ||
| 145 | unset($list);  | 
            ||
| 146 | |||
| 147 | // number and size of media  | 
            ||
| 148 | $list = array();  | 
            ||
| 149 |         search($list, $conf['mediadir'], array($this, 'searchCountCallback'), array('all'=>true)); | 
            ||
| 150 | $data['media_count'] = $list['file_count'];  | 
            ||
| 151 | $data['media_size'] = $list['file_size'];  | 
            ||
| 152 | $data['media_biggest'] = $list['file_max'];  | 
            ||
| 153 | $data['media_smallest'] = $list['file_min'];  | 
            ||
| 154 | $data['media_nscount'] = $list['dir_count'];  | 
            ||
| 155 | $data['media_nsnest'] = $list['dir_nest'];  | 
            ||
| 156 | if ($list['file_count']) $data['media_avg'] = $list['file_size'] / $list['file_count'];  | 
            ||
| 157 | unset($list);  | 
            ||
| 158 | |||
| 159 | // number and size of cache  | 
            ||
| 160 | $list = array();  | 
            ||
| 161 |         search($list, $conf['cachedir'], array($this, 'searchCountCallback'), array('all'=>true)); | 
            ||
| 162 | $data['cache_count'] = $list['file_count'];  | 
            ||
| 163 | $data['cache_size'] = $list['file_size'];  | 
            ||
| 164 | $data['cache_biggest'] = $list['file_max'];  | 
            ||
| 165 | $data['cache_smallest'] = $list['file_min'];  | 
            ||
| 166 | if ($list['file_count']) $data['cache_avg'] = $list['file_size'] / $list['file_count'];  | 
            ||
| 167 | unset($list);  | 
            ||
| 168 | |||
| 169 | // number and size of index  | 
            ||
| 170 | $list = array();  | 
            ||
| 171 |         search($list, $conf['indexdir'], array($this, 'searchCountCallback'), array('all'=>true)); | 
            ||
| 172 | $data['index_count'] = $list['file_count'];  | 
            ||
| 173 | $data['index_size'] = $list['file_size'];  | 
            ||
| 174 | $data['index_biggest'] = $list['file_max'];  | 
            ||
| 175 | $data['index_smallest'] = $list['file_min'];  | 
            ||
| 176 | if ($list['file_count']) $data['index_avg'] = $list['file_size'] / $list['file_count'];  | 
            ||
| 177 | unset($list);  | 
            ||
| 178 | |||
| 179 | // number and size of meta  | 
            ||
| 180 | $list = array();  | 
            ||
| 181 |         search($list, $conf['metadir'], array($this, 'searchCountCallback'), array('all'=>true)); | 
            ||
| 182 | $data['meta_count'] = $list['file_count'];  | 
            ||
| 183 | $data['meta_size'] = $list['file_size'];  | 
            ||
| 184 | $data['meta_biggest'] = $list['file_max'];  | 
            ||
| 185 | $data['meta_smallest'] = $list['file_min'];  | 
            ||
| 186 | if ($list['file_count']) $data['meta_avg'] = $list['file_size'] / $list['file_count'];  | 
            ||
| 187 | unset($list);  | 
            ||
| 188 | |||
| 189 | // number and size of attic  | 
            ||
| 190 | $list = array();  | 
            ||
| 191 |         search($list, $conf['olddir'], array($this, 'searchCountCallback'), array('all'=>true)); | 
            ||
| 192 | $data['attic_count'] = $list['file_count'];  | 
            ||
| 193 | $data['attic_size'] = $list['file_size'];  | 
            ||
| 194 | $data['attic_biggest'] = $list['file_max'];  | 
            ||
| 195 | $data['attic_smallest'] = $list['file_min'];  | 
            ||
| 196 | if ($list['file_count']) $data['attic_avg'] = $list['file_size'] / $list['file_count'];  | 
            ||
| 197 | $data['attic_oldest'] = $list['file_oldest'];  | 
            ||
| 198 | unset($list);  | 
            ||
| 199 | |||
| 200 | // user count  | 
            ||
| 201 |         if ($auth && $auth->canDo('getUserCount')) { | 
            ||
| 202 | $data['user_count'] = $auth->getUserCount();  | 
            ||
| 203 | }  | 
            ||
| 204 | |||
| 205 | // calculate edits per day  | 
            ||
| 206 | $list = @file($conf['metadir'].'/_dokuwiki.changes');  | 
            ||
| 207 | $count = count($list);  | 
            ||
| 208 |         if ($count > 2) { | 
            ||
| 209 | $first = (int) substr(array_shift($list), 0, 10);  | 
            ||
| 210 | $last = (int) substr(array_pop($list), 0, 10);  | 
            ||
| 211 | $dur = ($last - $first)/(60*60*24); // number of days in the changelog  | 
            ||
| 212 | $data['edits_per_day'] = $count/$dur;  | 
            ||
| 213 | }  | 
            ||
| 214 | unset($list);  | 
            ||
| 215 | |||
| 216 | // plugins  | 
            ||
| 217 | $data['plugin'] = plugin_list();  | 
            ||
| 218 | |||
| 219 | // pcre info  | 
            ||
| 220 |         if (defined('PCRE_VERSION')) $data['pcre_version'] = PCRE_VERSION; | 
            ||
| 221 |         $data['pcre_backtrack'] = ini_get('pcre.backtrack_limit'); | 
            ||
| 222 |         $data['pcre_recursion'] = ini_get('pcre.recursion_limit'); | 
            ||
| 223 | |||
| 224 | // php info  | 
            ||
| 225 | $data['os'] = PHP_OS;  | 
            ||
| 226 | $data['webserver'] = $_SERVER['SERVER_SOFTWARE'];  | 
            ||
| 227 | $data['php_version'] = phpversion();  | 
            ||
| 228 | $data['php_sapi'] = php_sapi_name();  | 
            ||
| 229 |         $data['php_memory'] = php_to_byte(ini_get('memory_limit')); | 
            ||
| 230 | $data['php_exectime'] = $phptime;  | 
            ||
| 231 | $data['php_extension'] = get_loaded_extensions();  | 
            ||
| 232 | |||
| 233 | // plugin usage data  | 
            ||
| 234 | $this->addPluginUsageData($data);  | 
            ||
| 235 | |||
| 236 | return $data;  | 
            ||
| 237 | }  | 
            ||
| 238 | |||
| 239 | /**  | 
            ||
| 240 | * Triggers event to let plugins add their own data  | 
            ||
| 241 | *  | 
            ||
| 242 | * @param $data  | 
            ||
| 243 | */  | 
            ||
| 244 | protected function addPluginUsageData(&$data)  | 
            ||
| 245 |     { | 
            ||
| 246 | $pluginsData = array();  | 
            ||
| 247 |         Event::createAndTrigger('PLUGIN_POPULARITY_DATA_SETUP', $pluginsData); | 
            ||
| 248 |         foreach ($pluginsData as $plugin => $d) { | 
            ||
| 249 |             if (is_array($d)) { | 
            ||
| 250 |                 foreach ($d as $key => $value) { | 
            ||
| 251 | $data['plugin_' . $plugin . '_' . $key] = $value;  | 
            ||
| 252 | }  | 
            ||
| 253 |             } else { | 
            ||
| 254 | $data['plugin_' . $plugin] = $d;  | 
            ||
| 255 | }  | 
            ||
| 256 | }  | 
            ||
| 257 | }  | 
            ||
| 258 | |||
| 259 | /**  | 
            ||
| 260 | * Callback to search and count the content of directories in DokuWiki  | 
            ||
| 261 | *  | 
            ||
| 293 | 
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: