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 |
||
| 10 | class Users_Account_Controller extends Controller implements PermissionProvider |
||
|
|
|||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * URL That you can access this from |
||
| 15 | * |
||
| 16 | * @config |
||
| 17 | */ |
||
| 18 | private static $url_segment = "users/account"; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Allowed sub-URL's on this controller |
||
| 22 | * |
||
| 23 | * @var array |
||
| 24 | * @config |
||
| 25 | */ |
||
| 26 | private static $allowed_actions = array( |
||
| 27 | "edit", |
||
| 28 | "changepassword", |
||
| 29 | "EditAccountForm", |
||
| 30 | "ChangePasswordForm", |
||
| 31 | ); |
||
| 32 | |||
| 33 | /** |
||
| 34 | * User account associated with this controller |
||
| 35 | * |
||
| 36 | * @var Member |
||
| 37 | */ |
||
| 38 | protected $member; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Getter for member |
||
| 42 | * |
||
| 43 | * @return Member |
||
| 44 | */ |
||
| 45 | public function getMember() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Setter for member |
||
| 52 | * |
||
| 53 | * @param Member $member A member to associate |
||
| 54 | * |
||
| 55 | * @return self |
||
| 56 | */ |
||
| 57 | public function setMember(Member $member) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Determine if current user requires verification (based on their |
||
| 65 | * account and Users verification setting). |
||
| 66 | * |
||
| 67 | * @return boolean |
||
| 68 | */ |
||
| 69 | public function RequireVerification() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Perorm setup when this controller is initialised |
||
| 80 | * |
||
| 81 | * @return void |
||
| 82 | */ |
||
| 83 | public function init() |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Get the link to this controller |
||
| 102 | * |
||
| 103 | * @param string $action The URL endpoint for this controller |
||
| 104 | * |
||
| 105 | * @return string |
||
| 106 | */ |
||
| 107 | public function Link($action = null) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get an absolute link to this controller |
||
| 117 | * |
||
| 118 | * @param string $action The URL endpoint for this controller |
||
| 119 | * |
||
| 120 | * @return string |
||
| 121 | */ |
||
| 122 | public function AbsoluteLink($action = null) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Get a relative (to the root url of the site) link to this |
||
| 129 | * controller |
||
| 130 | * |
||
| 131 | * @param string $action The URL endpoint for this controller |
||
| 132 | * |
||
| 133 | * @return string |
||
| 134 | */ |
||
| 135 | public function RelativeLink($action = null) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * If content controller exists, return it's menu function |
||
| 144 | * |
||
| 145 | * @param int $level Menu level to return. |
||
| 146 | * |
||
| 147 | * @return ArrayList |
||
| 148 | */ |
||
| 149 | View Code Duplication | public function getMenu($level = 1) |
|
| 156 | |||
| 157 | /** |
||
| 158 | * Shortcut for getMenu |
||
| 159 | * |
||
| 160 | * @param int $level Menu level to return. |
||
| 161 | * |
||
| 162 | * @return ArrayList |
||
| 163 | */ |
||
| 164 | public function Menu($level) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Display the currently outstanding orders for the current user |
||
| 171 | * |
||
| 172 | * @return HTMLText |
||
| 173 | */ |
||
| 174 | public function index() |
||
| 215 | |||
| 216 | public function edit() |
||
| 243 | |||
| 244 | public function changepassword() |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Factory for generating a profile form. The form can be expanded using an |
||
| 286 | * extension class and calling the updateEditProfileForm method. |
||
| 287 | * |
||
| 288 | * @return Form |
||
| 289 | */ |
||
| 290 | public function EditAccountForm() |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Factory for generating a change password form. The form can be expanded |
||
| 301 | * using an extension class and calling the updateChangePasswordForm method. |
||
| 302 | * |
||
| 303 | * @return Form |
||
| 304 | */ |
||
| 305 | public function ChangePasswordForm() |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Return a list of nav items for managing a users profile. You can add new |
||
| 331 | * items to this menu using the "updateAccountMenu" extension |
||
| 332 | * |
||
| 333 | * @return ArrayList |
||
| 334 | */ |
||
| 335 | public function getAccountMenu() |
||
| 378 | |||
| 379 | public function providePermissions() |
||
| 396 | } |
||
| 397 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.