Conditions | 5 |
Paths | 5 |
Total Lines | 28 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 8.7918 |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
1 | <?php |
||
19 | 2 | public static function makeFileName($fileAdder) |
|
20 | { |
||
21 | 2 | $fileName = $fileAdder->getFileName(); |
|
22 | if (!empty($fileName)) { |
||
23 | 2 | return $fileName; |
|
24 | } |
||
25 | $file = $fileAdder->getFile(); |
||
26 | |||
27 | if ($file instanceof UploadedFile) { |
||
28 | $path = $file->getRealPath(); |
||
29 | 2 | $extension = $file->getClientOriginalExtension(); |
|
30 | 2 | ||
31 | 2 | return static::transformFileName($path, $extension); |
|
32 | } |
||
33 | 2 | if ($file instanceof SymfonyFile) { |
|
34 | $path = $file->getRealPath(); |
||
35 | $extension = $file->getExtension(); |
||
36 | |||
37 | return static::transformFileName($path, $extension); |
||
38 | } |
||
39 | if (is_string($file)) { |
||
|
|||
40 | $path = $file; |
||
41 | $extension = pathinfo($file, PATHINFO_EXTENSION); |
||
42 | |||
43 | return static::transformFileName($path, $extension); |
||
44 | } |
||
45 | |||
46 | throw new \RuntimeException(__METHOD__ . ' needs a UploadedFile|SplFileInfo|string instance or a file path string'); |
||
47 | } |
||
57 |