| Total Complexity | 9 |
| Total Lines | 77 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | /** |
||
| 10 | * Files created during tests that should be unlinked during tear down. |
||
| 11 | * |
||
| 12 | * @var array |
||
| 13 | */ |
||
| 14 | protected $createdFiles = []; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Register a created file that should be unlinked during treardown. |
||
| 18 | * |
||
| 19 | * @param string $path |
||
| 20 | * |
||
| 21 | * @return void |
||
| 22 | */ |
||
| 23 | protected function registerCreatedFile($path) |
||
| 24 | { |
||
| 25 | $this->createdFiles[] = $path; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Unlink all registered files. |
||
| 30 | * |
||
| 31 | * @return void |
||
| 32 | */ |
||
| 33 | protected function removeRegisteredFiles() |
||
| 34 | { |
||
| 35 | foreach ($this->createdFiles as $path) { |
||
| 36 | if (is_dir($path)) { |
||
| 37 | $dir = new \DirectoryIterator($path); |
||
| 38 | |||
| 39 | foreach ($dir as $file) { |
||
| 40 | if (!$file->isDot()) { |
||
| 41 | unlink($file->getPathname()); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | rmdir($path); |
||
| 46 | } elseif (file_exists($path)) { |
||
| 47 | unlink($path); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } |
||
| 52 |