| Conditions | 10 |
| Paths | 14 |
| Total Lines | 37 |
| Code Lines | 27 |
| 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 |
||
| 25 | public static function deleteObsoleteTempDirs() { |
||
| 26 | $downloadsDirs = [ |
||
| 27 | 'site_installers' => dirname(dirname(dirname(dirname(__FILE__)))) . "/var/installer_cache", |
||
| 28 | 'silverbullet' => dirname(dirname(dirname(dirname(__FILE__)))) . "/var/silverbullet" |
||
| 29 | ]; |
||
| 30 | $tm = time(); |
||
| 31 | $i = 0; |
||
| 32 | $Cache = []; |
||
| 33 | $dbHandle = \core\DBConnection::handle("FRONTEND"); |
||
| 34 | $result = $dbHandle->exec("SELECT download_path FROM downloads WHERE download_path IS NOT NULL"); |
||
| 35 | while ($r = mysqli_fetch_row($result)) { |
||
| 36 | $e = explode('/', $r[0]); |
||
| 37 | $Cache[$e[count($e) - 2]] = 1; |
||
| 38 | } |
||
| 39 | foreach ($downloadsDirs as $downloads) { |
||
| 40 | if ($handle = opendir($downloads)) { |
||
| 41 | /* This is the correct way to loop over the directory. */ |
||
| 42 | while (false !== ($entry = readdir($handle))) { |
||
| 43 | if ($entry === '.' || $entry === '..' || $entry === '.gitignore') { |
||
| 44 | continue; |
||
| 45 | } |
||
| 46 | $ftime = $tm - filemtime($downloads . '/' . $entry); |
||
| 47 | if ($ftime < 3600) { |
||
| 48 | continue; |
||
| 49 | } |
||
| 50 | if (isset($Cache[$entry])) { |
||
| 51 | continue; |
||
| 52 | } |
||
| 53 | \core\common\Entity::rrmdir($downloads . '/' . $entry); |
||
| 54 | $i = $i + 1; |
||
| 55 | print "$entry\n"; |
||
| 56 | } |
||
| 57 | closedir($handle); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | return $i; |
||
| 61 | } |
||
| 62 | } |
||
| 63 |