Conditions | 6 |
Paths | 8 |
Total Lines | 53 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 3 |
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 |
||
176 | public function store(MoviesRequest $request) |
||
177 | { |
||
178 | $dateoutput = \DateTime::createFromFormat('d/m/Y', $request->date_release); |
||
179 | $movie = new Movies(); |
||
180 | $movie->type = $request->type; |
||
181 | $movie->title = $request->title; |
||
182 | $movie->synopsis = $request->synopsis; |
||
183 | $movie->description = $request->description; |
||
184 | $movie->trailer = $request->trailer; |
||
185 | $movie->date_release = $dateoutput; |
||
186 | $movie->visible = $request->visible; |
||
187 | $movie->cover = $request->cover; |
||
188 | $movie->languages = $request->lang; |
||
189 | $movie->categories_id = $request->categories_id; |
||
190 | $movie->note_presse = $request->note_presse; |
||
191 | $movie->distributeur = $request->distributeur; |
||
192 | |||
193 | $filename = ''; |
||
194 | |||
195 | if ($request->hasFile('image')) { |
||
196 | $file = $request->file('image'); |
||
197 | $filename = $file->getClientOriginalName(); // Récupère le nom original du fichier |
||
198 | $destinationPath = public_path().'/uploads/movies'; // Indique où stocker le fichier |
||
199 | $file->move($destinationPath, $filename); // Déplace le fichier |
||
200 | } |
||
201 | |||
202 | $movie->image = asset('uploads/movies/'.$filename); |
||
203 | $movie->save(); |
||
204 | |||
205 | $actors = $request->actors; |
||
206 | if (isset($actors)) { |
||
207 | foreach ($actors as $actor) { |
||
208 | DB::table('actors_movies') |
||
209 | ->insert([ |
||
210 | ['movies_id' => $movie->id, 'actors_id' => $actor], |
||
211 | ]); |
||
212 | } |
||
213 | } |
||
214 | |||
215 | $directors = $request->directors; |
||
216 | if (isset($directors)) { |
||
217 | foreach ($directors as $director) { |
||
218 | DB::table('directors_movies') |
||
219 | ->insert([ |
||
220 | ['movies_id' => $movie->id, 'directors_id' => $director], |
||
221 | ]); |
||
222 | } |
||
223 | } |
||
224 | |||
225 | Session::flash('success', "Le film {$movie->title} a été enregistré"); |
||
226 | |||
227 | return Redirect::route('movies_index'); |
||
228 | } |
||
229 | } |
||
230 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.