| Conditions | 11 |
| Paths | 36 |
| Total Lines | 58 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 36 | public function create(Request $request) |
||
| 37 | { |
||
| 38 | if (! \defined('STDOUT')) { |
||
| 39 | \define('STDOUT', fopen('php://stdout', 'wb')); |
||
| 40 | } |
||
| 41 | |||
| 42 | $title = 'Movie Add'; |
||
| 43 | |||
| 44 | // If no ID provided, show the add form |
||
| 45 | if (! $request->has('id')) { |
||
| 46 | return view('admin.movies.add', compact('title')); |
||
| 47 | } |
||
| 48 | |||
| 49 | // Validate the IMDB ID |
||
| 50 | $id = $request->input('id'); |
||
| 51 | |||
| 52 | if (! is_numeric($id)) { |
||
| 53 | return redirect()->back() |
||
| 54 | ->with('error', 'Invalid IMDB ID. Please enter only numeric digits (without the "tt" prefix).') |
||
| 55 | ->withInput(); |
||
| 56 | } |
||
| 57 | |||
| 58 | // Check if movie already exists |
||
| 59 | $movie = new Movie(['Settings' => null]); |
||
|
|
|||
| 60 | $movCheck = $movie->getMovieInfo($id); |
||
| 61 | |||
| 62 | if ($movCheck !== null) { |
||
| 63 | return redirect()->to('/admin/movie-edit?id='.$id) |
||
| 64 | ->with('warning', 'Movie already exists in the database. Redirected to edit page.'); |
||
| 65 | } |
||
| 66 | |||
| 67 | // Try to fetch and add the movie from TMDB |
||
| 68 | try { |
||
| 69 | $movieInfo = $movie->updateMovieInfo($id); |
||
| 70 | |||
| 71 | if ($movieInfo) { |
||
| 72 | // Link any existing releases to this movie |
||
| 73 | $forUpdate = Release::query()->where('imdbid', $id)->get(['id']); |
||
| 74 | if ($forUpdate !== null && $forUpdate->count() > 0) { |
||
| 75 | $movieInfoId = MovieInfo::query()->where('imdbid', $id)->first(['id']); |
||
| 76 | if ($movieInfoId !== null) { |
||
| 77 | foreach ($forUpdate as $rel) { |
||
| 78 | Release::query()->where('id', $rel->id)->update(['movieinfo_id' => $movieInfoId->id]); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | return redirect()->to('/admin/movie-list') |
||
| 84 | ->with('success', 'Movie successfully added! IMDB ID: '.$id); |
||
| 85 | } else { |
||
| 86 | return redirect()->back() |
||
| 87 | ->with('error', 'Could not fetch movie information from TMDB/IMDB. Please verify the IMDB ID is correct.') |
||
| 88 | ->withInput(); |
||
| 89 | } |
||
| 90 | } catch (\Exception $e) { |
||
| 91 | return redirect()->back() |
||
| 92 | ->with('error', 'Error adding movie: '.$e->getMessage()) |
||
| 93 | ->withInput(); |
||
| 94 | } |
||
| 204 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.