Passed
Push — master ( 06bf02...b3147e )
by Ferry
03:01
created

FileController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A postUploadFile() 0 24 4
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 5/10/2019
6
 * Time: 10:38 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\types\file;
10
11
use Illuminate\Routing\Controller as BaseController;
12
13
class FileController extends BaseController
14
{
15
    public function postUploadFile()
16
    {
17
        if(auth()->guest()) return redirect(cb()->getLoginUrl());
18
19
        $file = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $file is dead and can be removed.
Loading history...
20
        try {
21
22
            cb()->validation([
23
                'userfile' => 'required|mimes:' . implode(",",config('crudbooster.UPLOAD_FILE_EXTENSION_ALLOWED'))
24
            ]);
25
26
            $file = cb()->uploadFile('userfile', true);
27
28
        } catch (CBValidationException $e) {
0 ignored issues
show
Bug introduced by
The type crocodicstudio\crudboost...e\CBValidationException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
            return response()->json(['status'=>false,'message'=>$e->getMessage()]);
30
        } catch (\Exception $e) {
31
            return response()->json(['status'=>false,'message'=>$e->getMessage()]);
32
        }
33
34
        return response()->json([
35
            'status'=>true,
36
            'filename'=>basename($file),
37
            'full_url'=>asset($file),
38
            'url'=>$file
39
        ]);
40
    }
41
}