| Conditions | 3 |
| Paths | 3 |
| Total Lines | 59 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 22 |
| CRAP Score | 3.1707 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 36 | 2 | public function store(Request $request) |
|
| 37 | { |
||
| 38 | 2 | $request->validate([ |
|
| 39 | 2 | 'linkID' => 'required|exists:file_links,link_id' |
|
| 40 | ]); |
||
| 41 | |||
| 42 | 2 | $receiver = new FileReceiver('file', $request, HandlerFactory::classFromRequest($request)); |
|
| 43 | |||
| 44 | // Verify that the upload is valid and being processed |
||
| 45 | 2 | if($receiver->isUploaded() === false) |
|
| 46 | { |
||
| 47 | Log::error('Upload File Missing - ' . |
||
| 48 | /** @scrutinizer ignore-type */ |
||
| 49 | $request->toArray()); |
||
| 50 | throw new UploadMissingFileException(); |
||
| 51 | } |
||
| 52 | |||
| 53 | // Recieve and process the file |
||
| 54 | 2 | $save = $receiver->receive(); |
|
| 55 | |||
| 56 | // See if the uploade has finished |
||
| 57 | 2 | if($save->isFinished()) |
|
| 58 | { |
||
| 59 | 2 | $filePath = config('filesystems.paths.links').DIRECTORY_SEPARATOR.$request->linkID; |
|
| 60 | 2 | $file = $save->getFile(); |
|
| 61 | |||
| 62 | // Clean the file and store it |
||
| 63 | 2 | $fileName = Files::cleanFilename($filePath, $file->getClientOriginalName()); |
|
| 64 | 2 | $file->storeAs($filePath, $fileName); |
|
| 65 | |||
| 66 | // Place file in Files table of DB |
||
| 67 | 2 | $newFile = Files::create([ |
|
| 68 | 2 | 'file_name' => $fileName, |
|
| 69 | 2 | 'file_link' => $filePath.DIRECTORY_SEPARATOR |
|
| 70 | ]); |
||
| 71 | 2 | $fileID = $newFile->file_id; |
|
|
1 ignored issue
–
show
|
|||
| 72 | |||
| 73 | // Place the file in the file link files table of DB |
||
| 74 | 2 | FileLinkFiles::create([ |
|
| 75 | 2 | 'link_id' => $request->linkID, |
|
| 76 | 2 | 'file_id' => $fileID, |
|
| 77 | 2 | 'user_id' => Auth::user()->user_id, |
|
| 78 | 2 | 'upload' => 0 |
|
| 79 | ]); |
||
| 80 | |||
| 81 | // Log stored file |
||
| 82 | 2 | Log::info('File Stored', ['file_id' => $fileID, 'file_path' => $filePath.DIRECTORY_SEPARATOR.$fileName]); |
|
| 83 | |||
| 84 | 2 | return response()->json(['success' => true]); ; |
|
| 85 | } |
||
| 86 | |||
| 87 | // Get the current progress |
||
| 88 | $handler = $save->handler(); |
||
| 89 | |||
| 90 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
||
| 91 | Log::debug('File being uploaded. Percentage done - '.$handler->getPercentageDone()); |
||
| 92 | return response()->json([ |
||
| 93 | 'done' => $handler->getPercentageDone(), |
||
| 94 | 'status' => true |
||
| 95 | ]); |
||
| 181 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.