Conditions | 12 |
Paths | 36 |
Total Lines | 77 |
Code Lines | 51 |
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 |
||
87 | public function edit(Request $request) |
||
88 | { |
||
89 | $this->setAdminPrefs(); |
||
90 | |||
91 | $movie = new Movie(); |
||
92 | $meta_title = $title = 'Add Movie'; |
||
93 | |||
94 | // set the current action |
||
95 | $action = $request->input('action') ?? 'view'; |
||
96 | |||
97 | if ($request->has('id')) { |
||
98 | $id = $request->input('id'); |
||
99 | $mov = $movie->getMovieInfo($id); |
||
100 | |||
101 | if ($mov === null) { |
||
102 | abort(404, 'Movie you requested does not exist in database'); |
||
103 | } |
||
104 | |||
105 | switch ($action) { |
||
106 | case 'submit': |
||
107 | $coverLoc = resource_path().'/covers/movies/'.$id.'-cover.jpg'; |
||
108 | $backdropLoc = resource_path().'covers/movies/'.$id.'-backdrop.jpg'; |
||
109 | |||
110 | if ($_FILES['cover']['size'] > 0) { |
||
111 | $tmpName = $_FILES['cover']['tmp_name']; |
||
112 | $file_info = getimagesize($tmpName); |
||
113 | if (! empty($file_info)) { |
||
114 | move_uploaded_file($_FILES['cover']['tmp_name'], $coverLoc); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | if ($_FILES['backdrop']['size'] > 0) { |
||
119 | $tmpName = $_FILES['backdrop']['tmp_name']; |
||
120 | $file_info = getimagesize($tmpName); |
||
121 | if (! empty($file_info)) { |
||
122 | move_uploaded_file($_FILES['backdrop']['tmp_name'], $backdropLoc); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | $request->merge(['cover' => file_exists($coverLoc) ? 1 : 0]); |
||
127 | $request->merge(['backdrop' => file_exists($backdropLoc) ? 1 : 0]); |
||
128 | |||
129 | $movie->update([ |
||
130 | 'actors' => $request->input('actors'), |
||
131 | 'backdrop' => $request->input('backdrop'), |
||
132 | 'cover' => $request->input('cover'), |
||
133 | 'director' => $request->input('director'), |
||
134 | 'genre' => $request->input('genre'), |
||
135 | 'imdbid' => $id, |
||
136 | 'language' => $request->input('language'), |
||
137 | 'plot' => $request->input('plot'), |
||
138 | 'rating' => $request->input('rating'), |
||
139 | 'tagline' => $request->input('tagline'), |
||
140 | 'title' => $request->input('title'), |
||
141 | 'year' => $request->input('year'), |
||
142 | ]); |
||
143 | |||
144 | $movieInfo = MovieInfo::query()->where('imdbid', $id)->first(['id']); |
||
145 | if ($movieInfo !== null) { |
||
146 | Release::query()->where('imdbid', $id)->update(['movieinfo_id' => $movieInfo->id]); |
||
147 | } |
||
148 | |||
149 | return redirect('admin/movie-list'); |
||
150 | break; |
||
151 | case 'view': |
||
152 | default: |
||
153 | $meta_title = $title = 'Movie Edit'; |
||
154 | $this->smarty->assign('movie', $mov); |
||
155 | break; |
||
156 | } |
||
157 | } |
||
158 | |||
159 | $content = $this->smarty->fetch('movie-edit.tpl'); |
||
160 | |||
161 | $this->smarty->assign(compact('title', 'meta_title', 'content')); |
||
162 | |||
163 | $this->adminrender(); |
||
164 | } |
||
166 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.