| Conditions | 4 |
| Paths | 8 |
| Total Lines | 22 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 28 | 2 | public static function createArchiveFromDirectory(string $directoryPath, ?string $name = null): string |
|
| 29 | { |
||
| 30 | 2 | if (empty($name)) { |
|
| 31 | 1 | $name = self::generateRandomNameOfArchive(); |
|
| 32 | } |
||
| 33 | |||
| 34 | 2 | $zip = new ZipArchive(); |
|
| 35 | 2 | $zip->open($name, ZipArchive::CREATE); |
|
| 36 | |||
| 37 | 2 | $fixer = new PathFixer($directoryPath); |
|
| 38 | |||
| 39 | 2 | foreach (FSHelper::getDirectories($directoryPath) as $dir) { |
|
| 40 | 2 | $zip->addEmptyDir($fixer->fix($dir->getPathname())); |
|
| 41 | } |
||
| 42 | |||
| 43 | 2 | foreach (FSHelper::getFiles($directoryPath) as $file) { |
|
| 44 | 2 | $zip->addFile($file->getPathname(), $fixer->fix($file->getPathname())); |
|
| 45 | } |
||
| 46 | |||
| 47 | 2 | $zip->close(); |
|
| 48 | |||
| 49 | 2 | return $name; |
|
| 50 | } |
||
| 52 |