| Conditions | 6 |
| Paths | 4 |
| Total Lines | 74 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 32 |
| CRAP Score | 6.0226 |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 25 | public function store(Request $request) |
||
| 26 | { |
||
| 27 | 2 | // Validate the form |
|
| 28 | 2 | $request->validate([ |
|
| 29 | 'cust_id' => 'required', |
||
| 30 | 'name' => 'required', |
||
| 31 | 'type' => 'required' |
||
| 32 | ]); |
||
| 33 | 2 | ||
| 34 | $receiver = new FileReceiver('file', $request, HandlerFactory::classFromRequest($request)); |
||
| 35 | |||
| 36 | 2 | // Verify that the upload is valid and being processed |
|
| 37 | if($receiver->isUploaded() === false) |
||
| 38 | { |
||
| 39 | Log::error('Upload File Missing - ' . |
||
| 40 | /** @scrutinizer ignore-type */ |
||
| 41 | $request->toArray()); |
||
| 42 | throw new UploadMissingFileException(); |
||
| 43 | } |
||
| 44 | |||
| 45 | 2 | // Receive and process the file |
|
| 46 | $save = $receiver->receive(); |
||
| 47 | |||
| 48 | 2 | // See if the upload has finished |
|
| 49 | if($save->isFinished()) |
||
| 50 | 2 | { |
|
| 51 | // Determine if the note should go to the customer, or its parent |
||
| 52 | 2 | $details = Customers::find($request->cust_id); |
|
| 53 | 2 | if ($details->parent_id && $request->shared) |
|
| 54 | { |
||
| 55 | $request->cust_id = $details->parent_id; |
||
|
1 ignored issue
–
show
|
|||
| 56 | 2 | } |
|
| 57 | |||
| 58 | $file = $save->getFile(); |
||
| 59 | 2 | // Set file locationi and clean filename for duplicates |
|
| 60 | $filePath = config('filesystems.paths.customers').DIRECTORY_SEPARATOR.$request->cust_id; |
||
| 61 | 2 | $fileName = Files::cleanFileName($filePath, $file->getClientOriginalName()); |
|
| 62 | 2 | ||
| 63 | // Store the file |
||
| 64 | $file->storeAs($filePath, $fileName); |
||
| 65 | |||
| 66 | 2 | // Put the file in the database |
|
| 67 | $file = Files::create( |
||
| 68 | [ |
||
| 69 | 2 | 'file_name' => $fileName, |
|
| 70 | 2 | 'file_link' => $filePath.DIRECTORY_SEPARATOR |
|
| 71 | 2 | ]); |
|
| 72 | 2 | ||
| 73 | 2 | // Get information for system files table |
|
| 74 | 2 | $fileID = $file->file_id; |
|
| 75 | |||
| 76 | // Input the file into the customer files table |
||
| 77 | 2 | CustomerFiles::create([ |
|
| 78 | 2 | 'file_id' => $fileID, |
|
| 79 | 2 | 'file_type_id' => $request->type, |
|
| 80 | 'cust_id' => $request->cust_id, |
||
| 81 | 'user_id' => Auth::user()->user_id, |
||
| 82 | 'shared' => $request->shared ? 1 : 0, |
||
| 83 | 2 | 'name' => $request->name |
|
| 84 | ]); |
||
| 85 | 2 | ||
| 86 | 2 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
|
| 87 | 2 | Log::debug('Submitted Data - ', $request->toArray()); |
|
| 88 | 2 | Log::info('File added for Customer ID-'.$request->custID.' by User ID-'.Auth::user()->user_id.'. New File ID-'.$fileID); |
|
| 89 | } |
||
| 90 | |||
| 91 | // Get the current progress |
||
| 92 | $handler = $save->handler(); |
||
| 93 | |||
| 94 | 2 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
|
| 95 | Log::debug('File being uploaded. Percentage done - '.$handler->getPercentageDone()); |
||
| 96 | 2 | return response()->json([ |
|
| 97 | 2 | 'done' => $handler->getPercentageDone(), |
|
| 98 | 2 | 'status' => true |
|
| 99 | 2 | ]); |
|
| 160 |