| Total Complexity | 9 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class CleanSiteDirectory extends PreBuildTask |
||
| 17 | { |
||
| 18 | protected static string $message = 'Removing all files from build directory'; |
||
| 19 | |||
| 20 | public function handle(): void |
||
| 21 | { |
||
| 22 | if ($this->isItSafeToCleanOutputDirectory()) { |
||
| 23 | array_map('unlink', glob(Hyde::sitePath('*.{html,json}'), GLOB_BRACE)); |
||
| 24 | File::cleanDirectory(Hyde::siteMediaPath()); |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | public function printFinishMessage(): void |
||
| 29 | { |
||
| 30 | $this->newLine(); |
||
| 31 | } |
||
| 32 | |||
| 33 | protected function isItSafeToCleanOutputDirectory(): bool |
||
| 34 | { |
||
| 35 | if (! $this->isOutputDirectoryWhitelisted() && ! $this->askIfUnsafeDirectoryShouldBeEmptied()) { |
||
| 36 | $this->info('Output directory will not be emptied.'); |
||
| 37 | |||
| 38 | return false; |
||
| 39 | } |
||
| 40 | |||
| 41 | return true; |
||
| 42 | } |
||
| 43 | |||
| 44 | protected function isOutputDirectoryWhitelisted(): bool |
||
| 47 | } |
||
| 48 | |||
| 49 | protected function askIfUnsafeDirectoryShouldBeEmptied(): bool |
||
| 55 | )); |
||
| 56 | } |
||
| 57 | |||
| 58 | protected function safeOutputDirectories(): array |
||
| 61 | } |
||
| 62 | } |
||
| 63 |