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 |
||
| 14 | class ElggRole extends ElggObject { |
||
|
|
|||
| 15 | |||
| 16 | /** |
||
| 17 | * Protected permissions metadata |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $permissions; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Protected extends metdata |
||
| 24 | * @var string[] |
||
| 25 | */ |
||
| 26 | protected $extends; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | 27 | protected function initializeAttributes() { |
|
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | public function getDisplayName() { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Sets role permissions |
||
| 46 | * @return void |
||
| 47 | */ |
||
| 48 | 27 | public function setPermissions($permissions = array()) { |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Returns an array of permissions for this role |
||
| 54 | * @return array |
||
| 55 | */ |
||
| 56 | 24 | public function getPermissions() { |
|
| 73 | |||
| 74 | /** |
||
| 75 | * Set extends |
||
| 76 | * @param string[] $extends |
||
| 77 | * @return void |
||
| 78 | */ |
||
| 79 | 27 | public function setExtends($extends = array()) { |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Get extends |
||
| 85 | * @return string[] |
||
| 86 | */ |
||
| 87 | 24 | public function getExtends() { |
|
| 90 | |||
| 91 | /** |
||
| 92 | * Gets all reserved role names |
||
| 93 | * @return array The list of reserved role names |
||
| 94 | * @deprecated 2.0 |
||
| 95 | */ |
||
| 96 | public static function getReservedRoleNames() { |
||
| 99 | |||
| 100 | /** |
||
| 101 | * |
||
| 102 | * Checks if a role name is reserved in the system |
||
| 103 | * |
||
| 104 | * @param string $role_name The name of the role to check |
||
| 105 | * @return boolean True if the passed $role_name is a reserved role name |
||
| 106 | * @deprecated 2.0 |
||
| 107 | */ |
||
| 108 | public static function isReservedRoleName($role_name) { |
||
| 111 | |||
| 112 | /** |
||
| 113 | * |
||
| 114 | * Checks if this role is a reserved role |
||
| 115 | * @return boolean True if the current role is a reserved role |
||
| 116 | */ |
||
| 117 | 2 | public function isReservedRole() { |
|
| 120 | |||
| 121 | /** |
||
| 122 | * Obtain the list of users for the current role object |
||
| 123 | * |
||
| 124 | * @param array $options An array of $key => $value pairs accepted by {@link elgg_get_entities()} |
||
| 125 | * @return ElggUser[]|false The array of users having this role, false if no user found |
||
| 126 | */ |
||
| 127 | public function getUsers($options) { |
||
| 176 | |||
| 177 | } |
||
| 178 |
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.