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