| Conditions | 3 |
| Paths | 4 |
| Total Lines | 28 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | 8 | public static function upload($file): File |
|
| 20 | { |
||
| 21 | 8 | $name = $file->getClientOriginalName(); |
|
| 22 | 8 | $mime = $file->getMimeType(); |
|
| 23 | 8 | $size = $file->getSize(); |
|
| 24 | |||
| 25 | switch (true) { |
||
| 26 | 8 | case in_array($mime, static::IMAGE_MIME_TYPES): |
|
| 27 | 6 | $type = 'image'; |
|
| 28 | 6 | $class = Image::class; |
|
| 29 | 6 | break; |
|
| 30 | |||
| 31 | default: |
||
| 32 | 2 | $type = 'file'; |
|
| 33 | 2 | $class = File::class; |
|
| 34 | 2 | break; |
|
| 35 | } |
||
| 36 | |||
| 37 | 8 | $path = $file->store(str_plural($type)); |
|
| 38 | |||
| 39 | 8 | foreach (Config::get("uploadable.plugins.{$type}", []) as $plugin) { |
|
| 40 | 4 | $storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix(); |
|
| 41 | 4 | $fullPath = $storagePath . DIRECTORY_SEPARATOR . $path; |
|
| 42 | |||
| 43 | 4 | (new $plugin)->handle($fullPath); |
|
| 44 | } |
||
| 45 | |||
| 46 | 8 | return $class::create(compact('name', 'mime', 'size', 'path')); |
|
| 47 | } |
||
| 49 |