| Conditions | 6 |
| Paths | 5 |
| Total Lines | 105 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 127 | public function store(Request $request) |
||
| 128 | { |
||
| 129 | $request->validate([ |
||
| 130 | 'subject' => 'required', |
||
| 131 | 'systems' => 'required', |
||
| 132 | 'tipType' => 'required', |
||
| 133 | 'tip' => 'required', |
||
| 134 | ]); |
||
| 135 | |||
| 136 | $receiver = new FileReceiver('file', $request, HandlerFactory::classFromRequest($request)); |
||
| 137 | |||
| 138 | // Verify if there is a file to be processed or not (only Tech Tips can be processed without file) |
||
| 139 | if($receiver->isUploaded() === false && $request->tipType === 'Tech Tip') |
||
| 140 | { |
||
| 141 | $tipID = $this->createTip($request); |
||
| 142 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
||
| 143 | return response()->json(['url' => route('tips.details', [$tipID, urlencode($request->subject)])]); |
||
| 144 | } |
||
| 145 | else if($receiver->isUploaded() === false) |
||
| 146 | { |
||
| 147 | Log::error('Upload File Missing - '.$request->toArray()); |
||
| 148 | throw new UploadMissingFileException(); |
||
| 149 | } |
||
| 150 | |||
| 151 | // Receive and process the file |
||
| 152 | $save = $receiver->receive(); |
||
| 153 | |||
| 154 | if($save->isFinished()) |
||
| 155 | { |
||
| 156 | // if($request->tipType === 'Tech Tip') |
||
| 157 | // { |
||
| 158 | if(!$request->session()->has('newTechTip')) |
||
| 159 | { |
||
| 160 | $tipID = $this->createTip($request); |
||
| 161 | $request->session()->put('newTechTip', $tipID); |
||
| 162 | } |
||
| 163 | |||
| 164 | $tipID = session('newTechTip'); |
||
| 165 | |||
| 166 | // Log::debug('Tip ID - '.$tipID); |
||
| 167 | |||
| 168 | $file = $save->getFile(); |
||
| 169 | $path = config('filesystems.paths.tips').DIRECTORY_SEPARATOR.$tipID; |
||
| 170 | $fileName = Files::cleanFilename($path, $file->getClientOriginalName()); |
||
| 171 | $file->storeAs($path, $fileName); |
||
| 172 | |||
| 173 | $newFile = Files::create([ |
||
| 174 | 'file_name' => $fileName, |
||
| 175 | 'file_link' => $path.DIRECTORY_SEPARATOR |
||
| 176 | ]); |
||
| 177 | |||
| 178 | TechTipFiles::create([ |
||
| 179 | 'tip_id' => $tipID, |
||
| 180 | 'file_id' => $newFile->file_id |
||
| 181 | ]); |
||
| 182 | |||
| 183 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
||
| 184 | return response()->json(['url' => route('tips.details', [$tipID, urlencode($request->subject)])]); |
||
| 185 | // } |
||
| 186 | // else |
||
| 187 | // { |
||
| 188 | // $file = $save->getFile(); |
||
| 189 | // |
||
| 190 | // $sysArr = is_array($request->systems) ? $request->systems : json_decode($request->systems, true); |
||
| 191 | // foreach($sysArr as $sys) |
||
| 192 | // { |
||
| 193 | // $sysData = SystemTypes::where('sys_id', $sys['value'])->first(); |
||
| 194 | // $catName = SystemCategories::where('cat_id', $sysData->cat_id)->first()->name; |
||
| 195 | // $path = config('filesystems.paths.systems').DIRECTORY_SEPARATOR.strtolower($catName).DIRECTORY_SEPARATOR.$sysData->folder_location; |
||
| 196 | // $fileName = Files::cleanFilename($path, $file->getClientOriginalName()); |
||
| 197 | // |
||
| 198 | // Log::debug($fileName); |
||
| 199 | // Log::debug($path); |
||
| 200 | // |
||
| 201 | // $file->storeAs($path, $fileName); |
||
| 202 | // $file = Files::create([ |
||
| 203 | // 'file_name' => $fileName, |
||
| 204 | // 'file_link' => $path.DIRECTORY_SEPARATOR |
||
| 205 | // ]); |
||
| 206 | // |
||
| 207 | // $fileType = SystemFileTypes::where('description', $request->tipType)->first()->type_id; |
||
| 208 | // |
||
| 209 | // SystemFiles::create([ |
||
| 210 | // 'sys_id' => $sysData->sys_id, |
||
| 211 | // 'type_id' => $fileType, |
||
| 212 | // 'file_id' => $file->file_id, |
||
| 213 | // 'name' => $request->subject, |
||
| 214 | // 'description' => $request->tip, |
||
| 215 | // 'user_id' => Auth::user()->user_id |
||
| 216 | // ]); |
||
| 217 | // } |
||
| 218 | |||
| 219 | // Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
||
| 220 | // return response()->json(['url' => route('tips.details', [urlencode($sysData->name), urlencode($request->subject)])]); |
||
| 221 | // } |
||
| 222 | } |
||
| 223 | |||
| 224 | // Get the current progress |
||
| 225 | $handler = $save->handler(); |
||
| 226 | |||
| 227 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
||
| 228 | Log::debug('File being uploaded. Percentage done - '.$handler->getPercentageDone()); |
||
| 229 | return response()->json([ |
||
| 230 | 'done' => $handler->getPercentageDone(), |
||
| 231 | 'status' => true |
||
| 232 | ]); |
||
| 379 |