| Total Complexity | 5 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | trait InteractsWithDirectories |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Ensure the supplied directory exist by creating it if it does not. |
||
| 15 | * |
||
| 16 | * @param string $directory relative file path to the directory |
||
| 17 | */ |
||
| 18 | protected static function needsDirectory(string $directory): void |
||
| 19 | { |
||
| 20 | if (! Filesystem::exists($directory)) { |
||
| 21 | Filesystem::makeDirectory($directory, recursive: true); |
||
| 22 | } |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Ensure the supplied directories exist by creating them if they don't. |
||
| 27 | * |
||
| 28 | * @param array<string> $directories array with relative file paths to the directories |
||
| 29 | */ |
||
| 30 | protected static function needsDirectories(array $directories): void |
||
| 31 | { |
||
| 32 | foreach ($directories as $directory) { |
||
| 33 | static::needsDirectory($directory); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Ensure the supplied file's parent directory exists by creating it if it does not. |
||
| 39 | */ |
||
| 40 | protected static function needsParentDirectory(string $file, int $levels = 1): void |
||
| 43 | } |
||
| 44 | } |
||
| 45 |