Skip to content

Commit feb52be

Browse files
Fixed tmp dir creation
1 parent 26a273e commit feb52be

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Temp/TempDirResolver.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44

55
namespace Efabrica\PHPStanLatte\Temp;
66

7+
use RuntimeException;
8+
79
final class TempDirResolver
810
{
911
private string $tmpDir;
1012

1113
public function __construct(?string $tmpDir)
1214
{
13-
$this->tmpDir = $tmpDir ? rtrim($tmpDir, DIRECTORY_SEPARATOR) : sys_get_temp_dir() . '/phpstan-latte';
15+
$tmpDir = $tmpDir ? rtrim($tmpDir, DIRECTORY_SEPARATOR) : sys_get_temp_dir() . '/phpstan-latte';
16+
if (!is_dir($tmpDir)) {
17+
if (!@mkdir($tmpDir) && !is_dir($tmpDir)) {
18+
throw new RuntimeException(sprintf('Cannot create temp dir "%s"', $tmpDir));
19+
}
20+
}
21+
$tmpDir = realpath($tmpDir) ?: $tmpDir;
22+
if (!is_writable($tmpDir)) {
23+
throw new RuntimeException(sprintf('Temp dir "%s" is not writable', $tmpDir));
24+
}
25+
$this->tmpDir = $tmpDir;
1426
}
1527

1628
public function resolveCompileDir(): string

tests/config.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
parameters:
22
latte:
3-
tmpDir: %rootDir%/../../../tmp/phpstan-latte
43
resolveAllPossiblePaths: true
54
features:
65
transformDynamicFormControlNamesToString: true

0 commit comments

Comments
 (0)