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() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Get the link to this controller |
||
| 95 | * |
||
| 96 | * @param string $action |
||
| 97 | * @return string |
||
| 98 | */ |
||
| 99 | public function Link($action = null) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Get an absolute link to this controller |
||
| 109 | * |
||
| 110 | * @param string $action |
||
| 111 | * @return string |
||
| 112 | */ |
||
| 113 | public function AbsoluteLink($action = null) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Get a relative (to the root url of the site) link to this |
||
| 120 | * controller |
||
| 121 | * |
||
| 122 | * @param string $action |
||
| 123 | * @return string |
||
| 124 | */ |
||
| 125 | public function RelativeLink($action = null) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Display the currently outstanding orders for the current user |
||
| 134 | * |
||
| 135 | */ |
||
| 136 | View Code Duplication | public function index() |
|
| 152 | |||
| 153 | View Code Duplication | public function edit() |
|
| 170 | |||
| 171 | public function changepassword() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Factory for generating a profile form. The form can be expanded using an |
||
| 208 | * extension class and calling the updateEditProfileForm method. |
||
| 209 | * |
||
| 210 | * @return Form |
||
| 211 | */ |
||
| 212 | public function EditAccountForm() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Factory for generating a change password form. The form can be expanded |
||
| 223 | * using an extension class and calling the updateChangePasswordForm method. |
||
| 224 | * |
||
| 225 | * @return Form |
||
| 226 | */ |
||
| 227 | public function ChangePasswordForm() |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Return a list of nav items for managing a users profile. You can add new |
||
| 253 | * items to this menu using the "updateAccountMenu" extension |
||
| 254 | * |
||
| 255 | * @return ArrayList |
||
| 256 | */ |
||
| 257 | public function getAccountMenu() |
||
| 288 | |||
| 289 | public function providePermissions() |
||
| 306 | } |
||
| 307 |
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.