Conditions | 3 |
Paths | 3 |
Total Lines | 17 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php |
||
19 | public static function generateUniqueName(File $file, string $dir, $withPath = false) : string |
||
20 | { |
||
21 | // the provided path has to be a dir |
||
22 | if (!is_dir($dir)) { |
||
23 | throw new Exception("The dir provided: '{$dir}' isn't a valid one."); |
||
|
|||
24 | } |
||
25 | |||
26 | $path = tempnam($dir . '/', ''); |
||
27 | |||
28 | //this function creates a file (like touch) so, we have to delete it. |
||
29 | unlink($path); |
||
30 | $uniqueName = $path; |
||
31 | if (!$withPath) { |
||
32 | $uniqueName = str_replace($dir, '', $path); |
||
33 | } |
||
34 | |||
35 | return $uniqueName . '.' . strtolower($file->getExtension()); |
||
36 | } |
||
57 |