From a8a3985d2c7f4bb3d1d935bf03130c560224d384 Mon Sep 17 00:00:00 2001 From: Stein Magne Bjorklund <steinmb@smbjorklund.com> Date: Mon, 20 Sep 2021 20:25:55 +0200 Subject: [PATCH] Cleanup Importer::createModels() --- classes/Importer.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/classes/Importer.php b/classes/Importer.php index b3f3ac81..7862bd07 100644 --- a/classes/Importer.php +++ b/classes/Importer.php @@ -208,7 +208,7 @@ final class Importer return $namespaces; } - private function createModels($models) + private function createModels($models): void { try { foreach ($models as $k => $v) { @@ -217,17 +217,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