Skip to content

Commit 3e0fc57

Browse files
mnapolitillkruss
andauthored
Improve logs and error handling on directory creation (#41)
* Improve logs and error handling on directory creation * formatting --------- Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
1 parent 74e626c commit 3e0fc57

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/StorageDirectories.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace CacheWerk\BrefLaravelBridge;
44

5+
use RuntimeException;
6+
57
class StorageDirectories
68
{
79
/**
@@ -26,11 +28,15 @@ public static function create()
2628
self::Path . '/framework/views',
2729
];
2830

29-
foreach ($directories as $directory) {
30-
if (! is_dir($directory)) {
31-
fwrite(STDERR, "Creating storage directory: {$directory}" . PHP_EOL);
31+
$directories = array_filter($directories, static fn ($directory) => ! is_dir($directory));
3232

33-
mkdir($directory, 0755, true);
33+
if (count($directories)) {
34+
fwrite(STDERR, 'Creating storage directories: ' . implode(', ', $directories) . PHP_EOL);
35+
}
36+
37+
foreach ($directories as $directory) {
38+
if (! mkdir($directory, 0755, true) && ! is_dir($directory)) {
39+
throw new RuntimeException("Directory {$directory} could not be created");
3440
}
3541
}
3642
}

0 commit comments

Comments
 (0)