FileUploadController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
dl 0
loc 62
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B validateAndUpload() 0 41 6
A uploadFiles() 0 10 3
1
<?php
2
use LaravelRealtimeChat\Repositories\Team\TeamRepository;
3
use LaravelRealtimeChat\Repositories\Task\TaskRepository;
4
class FileUploadController extends AuthController {
5
  private $taskRepository;
6
7
        public function __construct(TeamRepository $teamRepository, TaskRepository $taskRepository) {
8
                $this->teamRepository = $teamRepository;
0 ignored issues
show
Bug introduced by
The property teamRepository is declared private in AuthController and cannot be accessed from this context.
Loading history...
9
                $this->taskRepository = $taskRepository;
10
        }
11
        public function uploadFiles($name) {
12
13
                switch ($name) {
14
                        case "chat":$folderName = "userUploads";
15
                                $this->validateAndUpload($folderName,false);//set true for db operations,else false
16
                                break;
17
18
                        case "task":$folderName = "userTaskFiles";
19
                                $this->validateAndUpload($folderName,true);
20
                                break;
21
                }
22
        }
23
24
25
 function validateAndUpload($folderName,$dbSave) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26
        $successStatus;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $successStatus seems to be never defined.
Loading history...
27
        $fileErr;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fileErr seems to be never defined.
Loading history...
28
        // Build the input for our validation
29
        $input      = Input::all();
0 ignored issues
show
Bug introduced by
The type Input 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...
30
        // Within the ruleset, make sure we let the validator know that this
31
        // file should be an image
32
        $rules      = array(
33
             'file' => 'max:100000000',
34
        );
35
        $validation = Validator::make($input, $rules);
36
37
        if ($validation->fails()) {
38
                return Response::make($validation->errors->first(), 400);
39
        }
40
41
        $file = Input::file('file');
42
        foreach ($file as $files) {
43
44
                $upload_success = $files->move('fusionmate/public/plugins/' . $folderName . '', $files->getClientOriginalName());
45
46
                $imgPath = $files->getClientOriginalName();
47
48
                if ($upload_success) {
49
                        if($dbSave){
50
                             $this->taskRepository->saveTaskFiles($imgPath);   
51
                        }
52
                        $fileErr = false;
53
                }
54
                else {
55
                        $fileErr = true;
56
                }
57
        }
58
        if (!$fileErr) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fileErr seems to be defined by a foreach iteration on line 42. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
59
60
                $successStatus = Response::json('success', 200);
61
        }
62
        else {
63
                $successStatus = Response::json('error', 400);
64
        }
65
        return $successStatus;
66
}
67
}