| Conditions | 8 |
| Paths | 7 |
| Total Lines | 30 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | public function clearDirectory($dir): void |
||
| 14 | { |
||
| 15 | if (!is_dir($dir)) { |
||
| 16 | return; |
||
| 17 | } |
||
| 18 | if (!($handle = opendir($dir))) { |
||
| 19 | return; |
||
| 20 | } |
||
| 21 | $specialFileNames = [ |
||
| 22 | '.htaccess', |
||
| 23 | '.gitignore', |
||
| 24 | '.gitkeep', |
||
| 25 | '.hgignore', |
||
| 26 | '.hgkeep', |
||
| 27 | ]; |
||
| 28 | while (($file = readdir($handle)) !== false) { |
||
| 29 | if ($file === '.' || $file === '..') { |
||
| 30 | continue; |
||
| 31 | } |
||
| 32 | if (in_array($file, $specialFileNames)) { |
||
| 33 | continue; |
||
| 34 | } |
||
| 35 | $path = $dir . DIRECTORY_SEPARATOR . $file; |
||
| 36 | if (is_dir($path)) { |
||
| 37 | \yii\helpers\FileHelper::removeDirectory($path); |
||
| 38 | } else { |
||
| 39 | unlink($path); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | closedir($handle); |
||
| 43 | } |
||
| 63 |