| 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 |
||
| 152 | public function store(MoviesRequest $request){ |
||
| 153 | |||
| 154 | $dateoutput = \DateTime::createFromFormat('d/m/Y',$request->date_release); |
||
| 155 | $movie = new Movies(); |
||
| 156 | $movie->type = $request->type; |
||
| 157 | $movie->title = $request->title; |
||
| 158 | $movie->synopsis = $request->synopsis; |
||
| 159 | $movie->description = $request->description; |
||
| 160 | $movie->trailer = $request->trailer; |
||
| 161 | $movie->date_release = $dateoutput; |
||
| 162 | $movie->visible = $request->visible; |
||
| 163 | $movie->cover = $request->cover; |
||
| 164 | $movie->languages = $request->lang; |
||
| 165 | $movie->categories_id = $request->categories_id; |
||
| 166 | $movie->note_presse = $request->note_presse; |
||
| 167 | $movie->distributeur = $request->distributeur; |
||
| 168 | |||
| 169 | $filename = ""; |
||
| 170 | |||
| 171 | if($request->hasFile('image')) { |
||
| 172 | $file = $request->file('image'); |
||
| 173 | $filename = $file->getClientOriginalName(); // Récupère le nom original du fichier |
||
| 174 | $destinationPath = public_path() . '/uploads/movies'; // Indique où stocker le fichier |
||
| 175 | $file->move($destinationPath, $filename); // Déplace le fichier |
||
| 176 | } |
||
| 177 | |||
| 178 | $movie->image = asset("uploads/movies/". $filename); |
||
| 179 | $movie->save(); |
||
| 180 | |||
| 181 | $actors = $request->actors; |
||
| 182 | if (isset($actors)) { |
||
| 183 | foreach ($actors as $actor) { |
||
| 184 | DB::table('actors_movies') |
||
| 185 | ->insert([ |
||
| 186 | ['movies_id' => $movie->id, 'actors_id' => $actor] |
||
| 187 | ]); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | $directors = $request->directors; |
||
| 192 | if (isset($directors)) { |
||
| 193 | foreach ($directors as $director) { |
||
| 194 | DB::table('directors_movies') |
||
| 195 | ->insert([ |
||
| 196 | ['movies_id' => $movie->id, 'directors_id' => $director] |
||
| 197 | ]); |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | |||
| 202 | Session::flash('success', "Le film {$movie->title} a été enregistré"); |
||
| 203 | return Redirect::route('movies_index'); |
||
| 204 | |||
| 205 | } |
||
| 206 | |||
| 227 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.