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 |
||
| 31 | class BaseCircle { |
||
| 32 | |||
| 33 | |||
| 34 | const CIRCLES_PERSONAL = 1; |
||
| 35 | const CIRCLES_HIDDEN = 2; |
||
| 36 | const CIRCLES_PRIVATE = 4; |
||
| 37 | const CIRCLES_PUBLIC = 8; |
||
| 38 | |||
| 39 | const CIRCLES_ALL = 15; |
||
| 40 | |||
| 41 | /** @var int */ |
||
| 42 | private $id; |
||
| 43 | |||
| 44 | /** @var L10N */ |
||
| 45 | protected $l10n; |
||
| 46 | |||
| 47 | /** @var string */ |
||
| 48 | private $uniqueId; |
||
| 49 | |||
| 50 | /** @var string */ |
||
| 51 | private $name; |
||
| 52 | |||
| 53 | /** @var Member */ |
||
| 54 | private $owner; |
||
| 55 | |||
| 56 | /** @var Member */ |
||
| 57 | private $user; |
||
| 58 | |||
| 59 | /** @var string */ |
||
| 60 | private $description; |
||
| 61 | |||
| 62 | /** @var int */ |
||
| 63 | private $type; |
||
| 64 | |||
| 65 | /** @var string */ |
||
| 66 | private $creation; |
||
| 67 | |||
| 68 | /** @var Member[] */ |
||
| 69 | private $members; |
||
| 70 | |||
| 71 | /** @var FederatedLink[] */ |
||
| 72 | private $links; |
||
| 73 | |||
| 74 | public function __construct($l10n, $type = -1, $name = '') { |
||
| 84 | |||
| 85 | |||
| 86 | public function setId($id) { |
||
| 91 | |||
| 92 | public function getId() { |
||
| 95 | |||
| 96 | |||
| 97 | /** |
||
| 98 | * @param string $uniqueId |
||
| 99 | * |
||
| 100 | * @return $this |
||
| 101 | */ |
||
| 102 | public function setUniqueId($uniqueId) { |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @return string |
||
| 110 | */ |
||
| 111 | public function getUniqueId() { |
||
| 114 | |||
| 115 | public function generateUniqueId() { |
||
| 119 | |||
| 120 | public function setName($name) { |
||
| 125 | |||
| 126 | public function getName() { |
||
| 129 | |||
| 130 | |||
| 131 | public function getOwner() { |
||
| 134 | |||
| 135 | public function setOwner($owner) { |
||
| 140 | |||
| 141 | |||
| 142 | /** |
||
| 143 | * @return Member |
||
| 144 | */ |
||
| 145 | public function getUser() { |
||
| 148 | |||
| 149 | public function setUser($user) { |
||
| 154 | |||
| 155 | |||
| 156 | public function setDescription($description) { |
||
| 161 | |||
| 162 | public function getDescription() { |
||
| 165 | |||
| 166 | |||
| 167 | public function setType($type) { |
||
| 172 | |||
| 173 | public function getType() { |
||
| 176 | |||
| 177 | |||
| 178 | public function setCreation($creation) { |
||
| 183 | |||
| 184 | public function getCreation() { |
||
| 187 | |||
| 188 | |||
| 189 | public function setMembers($members) { |
||
| 194 | |||
| 195 | public function getMembers() { |
||
| 198 | |||
| 199 | |||
| 200 | public function getRemote() { |
||
| 203 | |||
| 204 | public function addRemote($link) { |
||
| 207 | |||
| 208 | public function getRemoteFromToken($token) { |
||
| 217 | |||
| 218 | public function getRemoteFromAddressAndId($address, $id) { |
||
| 227 | |||
| 228 | |||
| 229 | public static function typeInt($type) { |
||
| 248 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.