| Conditions | 10 |
| Paths | 6 |
| Total Lines | 50 |
| Code Lines | 31 |
| 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 |
||
| 40 | public function edit(Request $request) |
||
| 41 | { |
||
| 42 | $this->setAdminPrefs(); |
||
| 43 | $games = new Games(['Settings' => null]); |
||
| 44 | $gen = new Genres(['Settings' => null]); |
||
| 45 | $meta_title = $title = 'Game Edit'; |
||
| 46 | |||
| 47 | // Set the current action. |
||
| 48 | $action = $request->input('action') ?? 'view'; |
||
| 49 | |||
| 50 | if ($request->has('id')) { |
||
| 51 | $id = $request->input('id'); |
||
| 52 | $game = $games->getGamesInfoById($id); |
||
| 53 | |||
| 54 | if (! $game) { |
||
| 55 | $this->show404(); |
||
| 56 | } |
||
| 57 | |||
| 58 | switch ($action) { |
||
| 59 | case 'submit': |
||
| 60 | $coverLoc = NN_COVERS.'games/'.$id.'.jpg'; |
||
| 61 | |||
| 62 | if ($_FILES['cover']['size'] > 0) { |
||
| 63 | $tmpName = $_FILES['cover']['tmp_name']; |
||
| 64 | $file_info = getimagesize($tmpName); |
||
| 65 | if (! empty($file_info)) { |
||
| 66 | move_uploaded_file($_FILES['cover']['tmp_name'], $coverLoc); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | $request->merge(['cover' => file_exists($coverLoc) ? 1 : 0]); |
||
| 71 | $request->merge(['releasedate' => (empty($request->input('releasedate')) || ! strtotime($request->input('releasedate'))) ? $game['releasedate'] : Carbon::parse($request->input('releasedate'))->timestamp]); |
||
| 72 | |||
| 73 | $games->update($id, $request->input('title'), $request->input('asin'), $request->input('url'), $request->input('publisher'), $request->input('releasedate'), $request->input('esrb'), $request->input('cover'), $request->input('trailerurl'), $request->input('genre')); |
||
| 74 | |||
| 75 | return redirect('admin/game-list'); |
||
| 76 | |||
| 77 | break; |
||
| 78 | |||
| 79 | case 'view': |
||
| 80 | default: |
||
| 81 | $this->smarty->assign('game', $game); |
||
| 82 | $this->smarty->assign('genres', $gen->getGenres(Genres::GAME_TYPE)); |
||
| 83 | break; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | $content = $this->smarty->fetch('game-edit.tpl'); |
||
| 88 | $this->smarty->assign(compact('title', 'meta_title', 'content')); |
||
| 89 | $this->adminrender(); |
||
| 90 | } |
||
| 92 |
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.