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 |
||
| 8 | class Users_Account_Controller extends Controller implements PermissionProvider |
||
|
|
|||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * URL That you can access this from |
||
| 13 | * |
||
| 14 | * @config |
||
| 15 | */ |
||
| 16 | private static $url_segment = "users/account"; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Allowed sub-URL's on this controller |
||
| 20 | * |
||
| 21 | * @var array |
||
| 22 | * @config |
||
| 23 | */ |
||
| 24 | private static $allowed_actions = array( |
||
| 25 | "edit", |
||
| 26 | "changepassword", |
||
| 27 | "EditAccountForm", |
||
| 28 | "ChangePasswordForm", |
||
| 29 | ); |
||
| 30 | |||
| 31 | /** |
||
| 32 | * User account associated with this controller |
||
| 33 | * |
||
| 34 | * @var Member |
||
| 35 | */ |
||
| 36 | protected $member; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Getter for member |
||
| 40 | * |
||
| 41 | * @return Member |
||
| 42 | */ |
||
| 43 | public function getMember() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Setter for member |
||
| 50 | * |
||
| 51 | * @param Member $member |
||
| 52 | * @return self |
||
| 53 | */ |
||
| 54 | public function setMember(Member $member) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Determine if current user requires verification (based on their |
||
| 62 | * account and Users verification setting). |
||
| 63 | * |
||
| 64 | * @return boolean |
||
| 65 | */ |
||
| 66 | public function RequireVerification() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Perorm setup when this controller is initialised |
||
| 77 | * |
||
| 78 | * @return void |
||
| 79 | */ |
||
| 80 | public function init() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Get the link to this controller |
||
| 99 | * |
||
| 100 | * @param string $action |
||
| 101 | * @return string|null |
||
| 102 | */ |
||
| 103 | public function Link($action = null) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Get an absolute link to this controller |
||
| 113 | * |
||
| 114 | * @param string $action |
||
| 115 | * @return string|null |
||
| 116 | */ |
||
| 117 | public function AbsoluteLink($action = null) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Get a relative (to the root url of the site) link to this |
||
| 124 | * controller |
||
| 125 | * |
||
| 126 | * @param string $action |
||
| 127 | * @return string|null |
||
| 128 | */ |
||
| 129 | public function RelativeLink($action = null) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * If content controller exists, return it's menu function |
||
| 138 | * @param int $level Menu level to return. |
||
| 139 | * @return ArrayList |
||
| 140 | */ |
||
| 141 | View Code Duplication | public function getMenu($level = 1) |
|
| 148 | |||
| 149 | public function Menu($level) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Display the currently outstanding orders for the current user |
||
| 156 | * |
||
| 157 | */ |
||
| 158 | public function index() |
||
| 191 | |||
| 192 | public function edit() |
||
| 215 | |||
| 216 | public function changepassword() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Factory for generating a profile form. The form can be expanded using an |
||
| 254 | * extension class and calling the updateEditProfileForm method. |
||
| 255 | * |
||
| 256 | * @return Form |
||
| 257 | */ |
||
| 258 | public function EditAccountForm() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Factory for generating a change password form. The form can be expanded |
||
| 269 | * using an extension class and calling the updateChangePasswordForm method. |
||
| 270 | * |
||
| 271 | * @return Form |
||
| 272 | */ |
||
| 273 | public function ChangePasswordForm() |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Return a list of nav items for managing a users profile. You can add new |
||
| 299 | * items to this menu using the "updateAccountMenu" extension |
||
| 300 | * |
||
| 301 | * @return ArrayList |
||
| 302 | */ |
||
| 303 | public function getAccountMenu() |
||
| 334 | |||
| 335 | public function providePermissions() |
||
| 352 | } |
||
| 353 |
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.