Passed
Pull Request — master (#265)
by Pascal
03:28
created

TemporaryDirectories::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\Filesystem;
4
5
use Illuminate\Filesystem\Filesystem;
6
7
class TemporaryDirectories
8
{
9
    /**
10
     * Root of the temporary directories.
11
     *
12
     * @var string
13
     */
14
    private $root;
15
16
    /**
17
     * Array of all directories
18
     *
19
     * @var array
20
     */
21
    private $directories = [];
22
23
    /**
24
     * Sets the root and removes the trailing slash.
25
     *
26
     * @param string $root
27
     */
28
    public function __construct(string $root)
29
    {
30
        $this->root = rtrim($root, '/');
31
    }
32
33
    /**
34
     * Returns the full path a of new temporary directory.
35
     *
36
     * @return string
37
     */
38
    public function create(): string
39
    {
40
        return $this->directories[] = $this->root . uniqid('/');
41
    }
42
43
    /**
44
     * Loop through all directories and delete them.
45
     */
46
    public function deleteAll(): void
47
    {
48
        $filesystem = new Filesystem;
49
50
        foreach ($this->directories as $directory) {
51
            $filesystem->deleteDirectory($directory);
52
        }
53
54
        $this->directories = [];
55
    }
56
}
57