Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 12 | class ProfileController extends LoginController |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Get details on item to load form with. |
||
| 17 | * |
||
| 18 | * @param integer $id get details on item with id. |
||
|
|
|||
| 19 | * |
||
| 20 | * @return object true if okey, false if something went wrong. |
||
| 21 | */ |
||
| 22 | 1 | public function getUserDetails($name) |
|
| 27 | |||
| 28 | /** |
||
| 29 | * Render profile page |
||
| 30 | * |
||
| 31 | * @return void |
||
| 32 | */ |
||
| 33 | public function renderProfile() |
||
| 34 | { |
||
| 35 | $this->checkIsLogin(); |
||
| 36 | |||
| 37 | $name = $this->di->get('session')->get("user"); |
||
| 38 | $user = $this->getUserDetails($name); |
||
| 39 | |||
| 40 | |||
| 41 | $views = [ |
||
| 42 | ["comment/user/profile/profile", ["user" => $user], "main"] |
||
| 43 | ]; |
||
| 44 | |||
| 45 | if ($user->authority == "admin") { |
||
| 46 | $views = [ |
||
| 47 | ["comment/admin/navbar", [], "main"], |
||
| 48 | ["comment/user/profile/profile", ["user" => $user], "main"] |
||
| 49 | ]; |
||
| 50 | } |
||
| 51 | |||
| 52 | $this->di->get("pageRenderComment")->renderPage([ |
||
| 53 | "views" => $views, |
||
| 54 | "title" => "$user->name" |
||
| 55 | ]); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Description. |
||
| 60 | * |
||
| 61 | * |
||
| 62 | * @return void |
||
| 63 | */ |
||
| 64 | View Code Duplication | public function getPostEditUser() |
|
| 65 | { |
||
| 66 | $name = $this->di->get('session')->get("user"); |
||
| 67 | $user = $this->getUserDetails($name); |
||
| 68 | |||
| 69 | $form = new EditProfileForm($this->di, $name); |
||
| 70 | $form->check(); |
||
| 71 | |||
| 72 | $views = [ |
||
| 73 | ["comment/user/profile/edit", ["form" => $form->getHTML(), "user" => $user], "main"] |
||
| 74 | ]; |
||
| 75 | |||
| 76 | $this->di->get("pageRenderComment")->renderPage([ |
||
| 77 | "views" => $views, |
||
| 78 | "title" => "Edit Profile" |
||
| 79 | ]); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Description. |
||
| 84 | * |
||
| 85 | * |
||
| 86 | * @return void |
||
| 87 | */ |
||
| 88 | View Code Duplication | public function getPostEditSecurity() |
|
| 105 | } |
||
| 106 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.