Total Complexity | 11 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Coverage | 95.45% |
Changes | 0 |
1 | <?php |
||
7 | class TemporaryFilename |
||
8 | { |
||
9 | /** @var string */ |
||
10 | private $filename; |
||
11 | |||
12 | /** @var bool */ |
||
13 | private $deleteOnDestruct; |
||
14 | |||
15 | 7 | public function __construct(string $dir = '', string $prefix = '', bool $deleteOnDestruct = true) |
|
16 | { |
||
17 | 7 | $this->deleteOnDestruct = $deleteOnDestruct; |
|
18 | 7 | $this->filename = (string) tempnam($dir, $prefix); |
|
19 | 7 | if ('' === $this->filename) { |
|
20 | throw new \RuntimeException('Cannot create the temporary filename'); |
||
21 | } |
||
22 | 7 | } |
|
23 | |||
24 | 7 | public function __destruct() |
|
28 | } |
||
29 | 7 | } |
|
30 | |||
31 | 2 | public function __toString() |
|
32 | { |
||
33 | 2 | return $this->filename(); |
|
34 | } |
||
35 | |||
36 | 7 | public function filename(): string |
|
37 | { |
||
38 | 7 | return $this->filename; |
|
39 | } |
||
40 | |||
41 | 1 | public function deleteOnDestruct(): bool |
|
42 | { |
||
43 | 1 | return $this->deleteOnDestruct; |
|
44 | } |
||
45 | |||
46 | 1 | public function setDeleteOnDestruct(bool $deleteOnDestruct) |
|
47 | { |
||
48 | 1 | $this->deleteOnDestruct = $deleteOnDestruct; |
|
49 | 1 | } |
|
50 | |||
51 | 6 | public function unlink() |
|
55 | } |
||
56 | 6 | } |
|
57 | } |
||
58 |