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