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 |
||
| 22 | class Request extends DataObject |
||
| 23 | { |
||
| 24 | private $email; |
||
| 25 | private $ip; |
||
| 26 | private $name; |
||
| 27 | /** @var string|null */ |
||
| 28 | private $comment; |
||
| 29 | private $status = "Open"; |
||
| 30 | private $date; |
||
| 31 | private $emailsent = 0; |
||
| 32 | private $emailconfirm; |
||
| 33 | private $reserved = 0; |
||
| 34 | private $useragent; |
||
| 35 | private $forwardedip; |
||
| 36 | private $hasComments = false; |
||
| 37 | private $hasCommentsResolved = false; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @throws Exception |
||
| 41 | */ |
||
| 42 | public function save() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @return string |
||
| 111 | */ |
||
| 112 | public function getIp() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @param string $ip |
||
| 119 | */ |
||
| 120 | 1 | public function setIp($ip) |
|
| 124 | |||
| 125 | /** |
||
| 126 | * @return string |
||
| 127 | */ |
||
| 128 | 1 | public function getName() |
|
| 132 | |||
| 133 | /** |
||
| 134 | * @param string $name |
||
| 135 | */ |
||
| 136 | 1 | public function setName($name) |
|
| 140 | |||
| 141 | /** |
||
| 142 | * @return string|null |
||
| 143 | */ |
||
| 144 | public function getComment() |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param string $comment |
||
| 151 | */ |
||
| 152 | public function setComment($comment) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return string |
||
| 159 | */ |
||
| 160 | public function getStatus() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @param string $status |
||
| 167 | */ |
||
| 168 | public function setStatus($status) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Returns the time the request was first submitted |
||
| 175 | * |
||
| 176 | * @return DateTimeImmutable |
||
| 177 | */ |
||
| 178 | public function getDate() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @return bool |
||
| 185 | */ |
||
| 186 | public function getEmailSent() |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param bool $emailSent |
||
| 193 | */ |
||
| 194 | public function setEmailSent($emailSent) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @todo allow this to return null instead |
||
| 201 | * @return int |
||
| 202 | */ |
||
| 203 | public function getReserved() |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @param int|null $reserved |
||
| 210 | */ |
||
| 211 | public function setReserved($reserved) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @return string |
||
| 223 | */ |
||
| 224 | public function getUserAgent() |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @param string $useragent |
||
| 231 | */ |
||
| 232 | public function setUserAgent($useragent) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @return string|null |
||
| 239 | */ |
||
| 240 | public function getForwardedIp() |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @param string|null $forwardedip |
||
| 247 | */ |
||
| 248 | public function setForwardedIp($forwardedip) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @return bool |
||
| 255 | */ |
||
| 256 | public function hasComments() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @return string |
||
| 282 | */ |
||
| 283 | public function getEmailConfirm() |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param string $emailconfirm |
||
| 290 | */ |
||
| 291 | public function setEmailConfirm($emailconfirm) |
||
| 295 | |||
| 296 | public function generateEmailConfirmationHash() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @return string|null |
||
| 303 | */ |
||
| 304 | 1 | public function getEmail() |
|
| 308 | |||
| 309 | /** |
||
| 310 | * @param string|null $email |
||
| 311 | */ |
||
| 312 | 1 | public function setEmail($email) |
|
| 316 | |||
| 317 | /** |
||
| 318 | * @return string |
||
| 319 | * @throws Exception |
||
| 320 | */ |
||
| 321 | public function getClosureReason() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Gets a value indicating whether the request was closed as created or not. |
||
| 348 | */ |
||
| 349 | public function getWasCreated() |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @return DateTime |
||
| 382 | */ |
||
| 383 | View Code Duplication | public function getClosureDate() |
|
| 398 | |||
| 399 | /** |
||
| 400 | * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal |
||
| 401 | * data to unauthorised* users. |
||
| 402 | * |
||
| 403 | * *:Not tool admins, check users, or the reserving user. |
||
| 404 | * |
||
| 405 | * @return string |
||
| 406 | * |
||
| 407 | * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events? |
||
| 408 | * Maybe depend on the last logged action timestamp? |
||
| 409 | */ |
||
| 410 | public function getRevealHash() |
||
| 421 | } |
||
| 422 |