From a79551adfdd061446e079072de9243d50cdf2b6b Mon Sep 17 00:00:00 2001 From: Stein Magne Bjorklund <steinmb@smbjorklund.com> Date: Mon, 20 Sep 2021 20:24:10 +0200 Subject: [PATCH] Cleanup Importer::createViews() --- classes/Importer.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/classes/Importer.php b/classes/Importer.php index e9ff9393..b3f3ac81 100644 --- a/classes/Importer.php +++ b/classes/Importer.php @@ -238,7 +238,7 @@ final class Importer } } - private function createViews($views) + private function createViews($views): void { try { foreach ($views as $k => $v) { @@ -247,17 +247,25 @@ final class Importer if (file_exists($path[$i])) { if (!is_dir($path[$i])) { unlink($path[$i]); - mkdir($path[$i]); + if (!mkdir($concurrentDirectory = $path[$i]) && !is_dir($concurrentDirectory)) { + throw new \RuntimeException( + sprintf('Directory "%s" was not created', $concurrentDirectory) + ); + } } - } else { - mkdir($path[$i]); + } elseif (!mkdir($concurrentDirectory = $path[$i]) && !is_dir($concurrentDirectory)) { + throw new \RuntimeException( + sprintf('Directory "%s" was not created', $concurrentDirectory) + ); } + chdir($path[$i]); } $fh = fopen(end($path), 'w'); fwrite($fh, $v); fclose($fh); + for ($i = 0; $i < sizeof($path) - 1; $i++) { chdir('..'); } -- GitLab