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