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