This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * rmarchiv.tk |
||
5 | * (c) 2016-2017 by Marcel 'ryg' Hering |
||
6 | */ |
||
7 | |||
8 | namespace App\Http\Controllers; |
||
9 | |||
10 | use Carbon\Carbon; |
||
11 | use App\Events\Obyx; |
||
12 | use App\Models\Game; |
||
13 | use App\Models\GamesFile; |
||
14 | use Illuminate\Http\Request; |
||
15 | use App\Models\GamesFilesType; |
||
16 | use App\Helpers\DatabaseHelper; |
||
17 | use App\Models\UserDownloadLog; |
||
18 | |||
19 | class GameFileController extends Controller |
||
20 | { |
||
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([ |
||
0 ignored issues
–
show
|
|||
47 | 'user_id' => \Auth::id(), |
||
48 | 'gamefile_id' => $id, |
||
49 | 'created_at' => Carbon::now(), |
||
50 | ]); |
||
51 | } else { |
||
52 | UserDownloadLog::insert([ |
||
0 ignored issues
–
show
The method
insert() does not exist on App\Models\UserDownloadLog . Did you maybe mean insertAndSetId() ?
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. ![]() |
|||
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; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
70 | $t = str_replace('{title}', $g->gametitle, $t); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
71 | $t = str_replace('{subtitle}', $g->gamesubtitle, $t); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
72 | $t = str_replace('{reltype}', $g->filetype, $t); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
73 | $t = str_replace('{relversion}', $g->fileversion, $t); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
74 | $t = str_replace('{relyear}', str_pad($g->fileyear, 2, 0, STR_PAD_LEFT), $t); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
75 | $t = str_replace('{relmonth}', str_pad($g->filemonth, 2, 0, STR_PAD_LEFT), $t); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
76 | $t = str_replace('{relday}', str_pad($g->fileday, 2, 0, STR_PAD_LEFT), $t); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
77 | $t = str_replace('{ext}', $g->fileextension, $t); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
78 | $newfilename = $t; |
||
79 | } |
||
80 | } |
||
81 | |||
82 | return response()->download($filepath, $newfilename); |
||
83 | } |
||
84 | |||
85 | public function download_wo_count(Request $request) |
||
86 | { |
||
87 | $filepath = storage_path('app/public/'.$request->get('filename')); |
||
88 | |||
89 | $newfilename = $request->get('id'); |
||
90 | |||
91 | return response()->download($filepath, $newfilename); |
||
92 | } |
||
93 | |||
94 | View Code Duplication | public function create($id) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
95 | { |
||
96 | $gamefiles = GamesFile::whereGameId($id) |
||
0 ignored issues
–
show
The method
orderBy does only exist in Illuminate\Database\Query\Builder , but not in App\Models\GamesFile .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
97 | ->orderBy('release_year', 'desc') |
||
98 | ->orderBy('release_month', 'desc') |
||
99 | ->orderBy('release_day', 'desc') |
||
100 | ->get(); |
||
101 | $game = Game::whereId($id)->first(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
102 | $filetypes = GamesFilesType::get(); |
||
103 | |||
104 | return view('games.gamefiles', [ |
||
105 | 'gamefiles' => $gamefiles, |
||
106 | 'game' => $game, |
||
107 | 'filetypes' => $filetypes, |
||
108 | ]); |
||
109 | } |
||
110 | |||
111 | public function store(Request $request, $id) |
||
112 | { |
||
113 | $this->validate($request, [ |
||
114 | 'uuid' => 'required', |
||
115 | 'version' => 'required', |
||
116 | 'releasedate_day' => 'required|not_in:0', |
||
117 | 'releasedate_month' => 'required|not_in:0', |
||
118 | 'releasedate_year' => 'required|not_in:0', |
||
119 | 'filetype' => 'required|not_in:0', |
||
120 | ]); |
||
121 | |||
122 | $storagetemp = 'temp/'.$request->get('uuid').'/file'; |
||
123 | $storagedest = 'games/'.$request->get('uuid').'.'.$request->get('ext'); |
||
124 | |||
125 | $meta['mime'] = \Storage::mimeType($storagetemp); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$meta was never initialized. Although not strictly required by PHP, it is generally a good practice to add $meta = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
126 | $meta['size'] = \Storage::size($storagetemp); |
||
127 | $meta['ext'] = $request->get('ext'); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
128 | |||
129 | $exists = \Storage::disk('local')->exists($storagetemp); |
||
130 | |||
131 | if ($exists === true) { |
||
132 | \Storage::move($storagetemp, $storagedest); |
||
133 | |||
134 | \DB::table('games_files')->insert([ |
||
135 | 'game_id' => $id, |
||
136 | 'filesize' => $meta['size'], |
||
137 | 'extension' => $meta['ext'], |
||
138 | 'release_type' => $request->get('filetype'), |
||
139 | 'release_version' => $request->get('version'), |
||
140 | 'release_day' => $request->get('releasedate_day'), |
||
141 | 'release_month' => $request->get('releasedate_month'), |
||
142 | 'release_year' => $request->get('releasedate_year'), |
||
143 | 'user_id' => \Auth::id(), |
||
144 | 'filename' => $storagedest, |
||
145 | 'created_at' => Carbon::now(), |
||
146 | ]); |
||
147 | |||
148 | event(new Obyx('gamefile-add', \Auth::id())); |
||
149 | } |
||
150 | |||
151 | DatabaseHelper::setReleaseInfos($id); |
||
152 | |||
153 | return redirect()->route('gamefiles.index', [$id]); |
||
154 | } |
||
155 | |||
156 | public function destroy($id, $fileid) |
||
157 | { |
||
158 | $gf = GamesFile::whereId($fileid)->first(); |
||
159 | \Storage::delete($gf->filename); |
||
160 | |||
161 | $gf->delete(); |
||
162 | |||
163 | return redirect()->route('gamefiles.index', [$id]); |
||
164 | } |
||
165 | |||
166 | public function edit($id, $gamefileid) |
||
0 ignored issues
–
show
|
|||
167 | { |
||
168 | $gamefile = GamesFile::whereId($gamefileid)->first(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
169 | $filetypes = GamesFilesType::get(); |
||
170 | |||
171 | return view('games.gamefiles_edit', [ |
||
172 | 'gamefile' => $gamefile, |
||
173 | 'filetypes' => $filetypes, |
||
174 | ]); |
||
175 | } |
||
176 | |||
177 | public function restore($gamefileid) |
||
178 | { |
||
179 | $gamefile = GamesFile::whereId($gamefileid)->first(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
180 | $gamefile->forbidden = 0; |
||
181 | $gamefile->reason = ''; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
182 | $gamefile->save(); |
||
183 | |||
184 | return redirect()->back(); |
||
185 | } |
||
186 | |||
187 | public function update(Request $request, $id, $gamefileid) |
||
188 | { |
||
189 | $this->validate($request, [ |
||
190 | //'uuid' => 'required', |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
191 | 'version' => 'required', |
||
192 | 'releasedate_day' => 'required|not_in:0', |
||
193 | 'releasedate_month' => 'required|not_in:0', |
||
194 | 'releasedate_year' => 'required|not_in:0', |
||
195 | 'filetype' => 'required|not_in:0', |
||
196 | ]); |
||
197 | |||
198 | $gamefile = GamesFile::whereId($gamefileid)->first(); |
||
199 | |||
200 | $gamefile->release_version = $request->get('version'); |
||
201 | $gamefile->release_day = $request->get('releasedate_day'); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
202 | $gamefile->release_month = $request->get('releasedate_month'); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
203 | $gamefile->release_year = $request->get('releasedate_year'); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
204 | $gamefile->release_type = $request->get('filetype'); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
205 | |||
206 | if ($request->get('uuid')) { |
||
207 | //Create Backupfile |
||
208 | if (\Storage::exists($gamefile->filename)) { |
||
209 | \Storage::move($gamefile->filename, $gamefile->filename.'-'.time()); |
||
210 | } |
||
211 | |||
212 | $storagetemp = 'temp/'.$request->get('uuid').'/file'; |
||
213 | $storagedest = 'games/'.$request->get('uuid').'.'.$request->get('ext'); |
||
214 | |||
215 | $meta['mime'] = \Storage::mimeType($storagetemp); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$meta was never initialized. Although not strictly required by PHP, it is generally a good practice to add $meta = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
216 | $meta['size'] = \Storage::size($storagetemp); |
||
217 | $meta['ext'] = $request->get('ext'); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
218 | |||
219 | $exists = \Storage::disk('local')->exists($storagetemp); |
||
220 | |||
221 | if ($exists === true) { |
||
222 | \Storage::move($storagetemp, $storagedest); |
||
223 | $gamefile->filesize = $meta['size']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
224 | $gamefile->extension = $meta['ext']; |
||
225 | $gamefile->filename = $storagedest; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
226 | } |
||
227 | } |
||
228 | |||
229 | if ($request->get('forbidden') && ($request->get('forbidden') != '')) { |
||
230 | $gamefile->forbidden = 1; |
||
231 | $gamefile->reason = $request->get('forbidden'); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
232 | } else { |
||
233 | $gamefile->forbidden = 0; |
||
234 | $gamefile->reason = ''; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
235 | } |
||
236 | |||
237 | $gamefile->save(); |
||
238 | |||
239 | DatabaseHelper::setReleaseInfos($id); |
||
240 | |||
241 | return redirect()->route('gamefiles.index', [$id]); |
||
242 | } |
||
243 | } |
||
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.