Test Failed
Push — master ( fcc3b8...91cd3f )
by Yuvaraj
04:41
created

FileUploadController::uploadFiles()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
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
}