| Conditions | 8 |
| Paths | 6 |
| Total Lines | 84 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 72 |
| 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 |
||
| 81 | public function store(Request $request) |
||
| 82 | { |
||
| 83 | $request->validate([ |
||
| 84 | 'name' => 'required', |
||
| 85 | 'expire' => 'required', |
||
| 86 | 'customerID' => 'exists:customers,cust_id|nullable' |
||
| 87 | ]); |
||
| 88 | |||
| 89 | if(!empty($request->file)) |
||
| 90 | { |
||
| 91 | $receiver = new FileReceiver('file', $request, HandlerFactory::classFromRequest($request)); |
||
| 92 | |||
| 93 | // Verify that the upload is valid and being processed |
||
| 94 | if($receiver->isUploaded() === false) |
||
| 95 | { |
||
| 96 | Log::error('Upload File Missing - ' . |
||
| 97 | /** @scrutinizer ignore-type */ |
||
| 98 | $request->toArray()); |
||
| 99 | throw new UploadMissingFileException(); |
||
| 100 | } |
||
| 101 | |||
| 102 | // Recieve and process the file |
||
| 103 | $save = $receiver->receive(); |
||
| 104 | |||
| 105 | // See if the uploade has finished |
||
| 106 | if($save->isFinished()) |
||
| 107 | { |
||
| 108 | $this->saveFile($save->getFile()); |
||
| 109 | |||
| 110 | return 'uploaded successfully'; |
||
| 111 | } |
||
| 112 | |||
| 113 | // Get the current progress |
||
| 114 | $handler = $save->handler(); |
||
| 115 | |||
| 116 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
||
| 117 | Log::debug('File being uploaded. Percentage done - '.$handler->getPercentageDone()); |
||
| 118 | return response()->json([ |
||
| 119 | 'done' => $handler->getPercentageDone(), |
||
| 120 | 'status' => true |
||
| 121 | ]); |
||
| 122 | } |
||
| 123 | |||
| 124 | // If there are no files being uploaded or the file uploade process is done |
||
| 125 | if(isset($request->_completed) && $request->_completed) |
||
| 126 | { |
||
| 127 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
||
| 128 | Log::debug('Link data submitted. Data - ', |
||
| 129 | /** @scrutinizer ignore-type */ |
||
| 130 | $request->toArray()); |
||
| 131 | $linkID = $this->createLink($request); |
||
| 132 | if($request->session()->has('newLinkFile')) |
||
| 133 | { |
||
| 134 | // If there were files uploaded to the link, process them |
||
| 135 | $files = session('newLinkFile'); |
||
| 136 | $path = config('filesystems.paths.links').DIRECTORY_SEPARATOR.$linkID; |
||
| 137 | |||
| 138 | foreach($files as $file) |
||
| 139 | { |
||
| 140 | $data = Files::find($file); |
||
| 141 | // Move the file to the proper folder |
||
| 142 | Storage::move($data->file_link.$data->file_name, $path.DIRECTORY_SEPARATOR.$data->file_name); |
||
|
2 ignored issues
–
show
|
|||
| 143 | // Update file link in DB |
||
| 144 | $data->update([ |
||
| 145 | 'file_link' => $path.DIRECTORY_SEPARATOR |
||
| 146 | ]); |
||
| 147 | // Attach file to the link |
||
| 148 | FileLinkFiles::create([ |
||
| 149 | 'link_id' => $linkID, |
||
| 150 | 'file_id' => $data->file_id, |
||
|
1 ignored issue
–
show
|
|||
| 151 | 'user_id' => Auth::user()->user_id, |
||
| 152 | 'upload' => 0 |
||
| 153 | ]); |
||
| 154 | |||
| 155 | Log::debug('File Added for link ID-'.$linkID.'. File ID-'.$data->file_id); |
||
| 156 | } |
||
| 157 | |||
| 158 | $request->session()->forget('newLinkFile'); |
||
| 159 | } |
||
| 160 | |||
| 161 | return response()->json(['link' => $linkID, 'name' => Str::slug($request->name)]); |
||
| 162 | } |
||
| 163 | |||
| 164 | return response()->json(['complete' => false]); |
||
| 165 | } |
||
| 319 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.