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