Conditions | 18 |
Paths | 9218 |
Total Lines | 84 |
Code Lines | 47 |
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 |
||
94 | public function showMovie(Request $request, string $imdbid) |
||
95 | { |
||
96 | $movie = new Movie(['Settings' => $this->settings]); |
||
97 | |||
98 | // Get movie info |
||
99 | $movieInfo = $movie->getMovieInfo($imdbid); |
||
100 | |||
101 | if (! $movieInfo) { |
||
102 | return redirect()->route('Movies')->with('error', 'Movie not found'); |
||
103 | } |
||
104 | |||
105 | // Get all releases for this movie |
||
106 | $rslt = $movie->getMovieRange(1, [], 0, 1000, '', -1, $this->userdata->categoryexclusions); |
||
107 | |||
108 | // Filter to only this movie's IMDB ID |
||
109 | $movieData = collect($rslt)->firstWhere('imdbid', $imdbid); |
||
110 | |||
111 | if (! $movieData) { |
||
112 | return redirect()->route('Movies')->with('error', 'No releases found for this movie'); |
||
113 | } |
||
114 | |||
115 | // Process movie data - ensure we handle both objects and arrays |
||
116 | if (is_object($movieInfo)) { |
||
117 | // If it's an Eloquent model, use toArray() |
||
118 | if (method_exists($movieInfo, 'toArray')) { |
||
119 | $movieArray = $movieInfo->toArray(); |
||
120 | } else { |
||
121 | $movieArray = get_object_vars($movieInfo); |
||
122 | } |
||
123 | } else { |
||
124 | $movieArray = $movieInfo; |
||
125 | } |
||
126 | |||
127 | // Ensure we have at least the basic fields |
||
128 | if (empty($movieArray['title'])) { |
||
129 | $movieArray['title'] = 'Unknown Title'; |
||
130 | } |
||
131 | if (empty($movieArray['imdbid'])) { |
||
132 | $movieArray['imdbid'] = $imdbid; |
||
133 | } |
||
134 | |||
135 | // Only process fields if they exist and are not empty |
||
136 | if (! empty($movieArray['genre'])) { |
||
137 | $movieArray['genre'] = makeFieldLinks($movieArray, 'genre', 'movies'); |
||
138 | } |
||
139 | if (! empty($movieArray['actors'])) { |
||
140 | $movieArray['actors'] = makeFieldLinks($movieArray, 'actors', 'movies'); |
||
141 | } |
||
142 | if (! empty($movieArray['director'])) { |
||
143 | $movieArray['director'] = makeFieldLinks($movieArray, 'director', 'movies'); |
||
144 | } |
||
145 | |||
146 | // Add cover image URL using helper function |
||
147 | $movieArray['cover'] = getReleaseCover($movieArray); |
||
148 | |||
149 | // Process all releases |
||
150 | $releaseNames = isset($movieData->grp_release_name) ? explode('#', $movieData->grp_release_name) : []; |
||
151 | $releaseSizes = isset($movieData->grp_release_size) ? explode(',', $movieData->grp_release_size) : []; |
||
152 | $releaseGuids = isset($movieData->grp_release_guid) ? explode(',', $movieData->grp_release_guid) : []; |
||
153 | $releasePostDates = isset($movieData->grp_release_postdate) ? explode(',', $movieData->grp_release_postdate) : []; |
||
154 | $releaseAddDates = isset($movieData->grp_release_adddate) ? explode(',', $movieData->grp_release_adddate) : []; |
||
155 | |||
156 | $releases = []; |
||
157 | foreach ($releaseNames as $index => $releaseName) { |
||
158 | if ($releaseName && isset($releaseGuids[$index])) { |
||
159 | $releases[] = [ |
||
160 | 'name' => $releaseName, |
||
161 | 'guid' => $releaseGuids[$index], |
||
162 | 'size' => $releaseSizes[$index] ?? 0, |
||
163 | 'postdate' => $releasePostDates[$index] ?? null, |
||
164 | 'adddate' => $releaseAddDates[$index] ?? null, |
||
165 | ]; |
||
166 | } |
||
167 | } |
||
168 | |||
169 | $this->viewData = array_merge($this->viewData, [ |
||
170 | 'movie' => $movieArray, |
||
171 | 'releases' => $releases, |
||
172 | 'meta_title' => ($movieArray['title'] ?? 'Movie').' - Movie Details', |
||
173 | 'meta_keywords' => 'movie,details,releases', |
||
174 | 'meta_description' => 'View all releases for '.($movieArray['title'] ?? 'this movie'), |
||
175 | ]); |
||
176 | |||
177 | return view('movies.viewmoviefull', $this->viewData); |
||
178 | } |
||
219 |
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.