OsHelper::makeTempDirectory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Gameap\Helpers;
4
5
class OsHelper
6
{
7
    public static function tempFile(): string
8
    {
9
        return tempnam(self::tempDirectory(), self::randomFileName());
10
    }
11
12
    public static function tempDirectory(): string
13
    {
14
        return sys_get_temp_dir();
15
    }
16
17
    public static function makeTempDirectory(): string
18
    {
19
        $directory = self::tempDirectory() . "/" . self::randomFileName();
20
        mkdir($directory);
21
22
        return $directory;
23
    }
24
25
    private static function randomFileName(): string
26
    {
27
        $bytes = random_bytes(6);
28
        return bin2hex($bytes);
29
    }
30
}
31