| Conditions | 4 |
| Paths | 6 |
| Total Lines | 63 |
| Code Lines | 46 |
| 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 |
||
| 21 | public function download($id) |
||
| 22 | { |
||
| 23 | \DB::table('games_files') |
||
| 24 | ->where('id', '=', $id) |
||
| 25 | ->increment('downloadcount'); |
||
| 26 | |||
| 27 | $g = \DB::table('games') |
||
| 28 | ->select([ |
||
| 29 | 'games.title as gametitle', |
||
| 30 | 'games.subtitle as gamesubtitle', |
||
| 31 | 'games_files.filename as filename', |
||
| 32 | 'games_files.extension as fileextension', |
||
| 33 | 'games_files_types.title as filetype', |
||
| 34 | 'games_files.release_version as fileversion', |
||
| 35 | 'games_files.release_day as fileday', |
||
| 36 | 'games_files.release_month as filemonth', |
||
| 37 | 'games_files.release_year as fileyear', |
||
| 38 | ]) |
||
| 39 | ->leftJoin('games_files', 'games.id', '=', 'games_files.game_id') |
||
| 40 | ->leftJoin('games_files_types', 'games_files.release_type', '=', 'games_files_types.id') |
||
| 41 | ->where('games_files.id', '=', $id) |
||
| 42 | ->limit(1) |
||
| 43 | ->first(); |
||
| 44 | |||
| 45 | if (\Auth::check()) { |
||
| 46 | UserDownloadLog::insert([ |
||
|
|
|||
| 47 | 'user_id' => \Auth::id(), |
||
| 48 | 'gamefile_id' => $id, |
||
| 49 | 'created_at' => Carbon::now(), |
||
| 50 | ]); |
||
| 51 | } else { |
||
| 52 | UserDownloadLog::insert([ |
||
| 53 | 'user_id' => 0, |
||
| 54 | 'gamefile_id' => $id, |
||
| 55 | 'created_at' => Carbon::now(), |
||
| 56 | ]); |
||
| 57 | } |
||
| 58 | |||
| 59 | $filepath = storage_path('app/public/'.$g->filename); |
||
| 60 | |||
| 61 | $newfilename = $g->gametitle.' - '.$g->gamesubtitle.' ['.$g->filetype.'-'.$g->fileversion.']-'.str_pad($g->fileyear, 2, 0, STR_PAD_LEFT) |
||
| 62 | .'-'.str_pad($g->filemonth, 2, 0, STR_PAD_LEFT).'-'.str_pad($g->fileday, 2, 0, STR_PAD_LEFT).'.'.$g->fileextension; |
||
| 63 | |||
| 64 | if (\Auth::check()) { |
||
| 65 | //Check for existing download Template |
||
| 66 | if (\Auth::user()->settings->download_template != '') { |
||
| 67 | |||
| 68 | //Replace all stuff for download template |
||
| 69 | $t = \Auth::user()->settings->download_template; |
||
| 70 | $t = str_replace('{title}', $g->gametitle, $t); |
||
| 71 | $t = str_replace('{subtitle}', $g->gamesubtitle, $t); |
||
| 72 | $t = str_replace('{reltype}', $g->filetype, $t); |
||
| 73 | $t = str_replace('{relversion}', $g->fileversion, $t); |
||
| 74 | $t = str_replace('{relyear}', str_pad($g->fileyear, 2, 0, STR_PAD_LEFT), $t); |
||
| 75 | $t = str_replace('{relmonth}', str_pad($g->filemonth, 2, 0, STR_PAD_LEFT), $t); |
||
| 76 | $t = str_replace('{relday}', str_pad($g->fileday, 2, 0, STR_PAD_LEFT), $t); |
||
| 77 | $t = str_replace('{ext}', $g->fileextension, $t); |
||
| 78 | $newfilename = $t; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | return response()->download($filepath, $newfilename); |
||
| 83 | } |
||
| 84 | |||
| 244 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.