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 |
||
| 26 | View Code Duplication | class Mailbox extends Response |
|
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var string Name of the mailbox. |
||
| 30 | */ |
||
| 31 | private $name; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var int Count of new messages in the mailbox. |
||
| 35 | */ |
||
| 36 | private $newMessages; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var int Count of old messages in the mailbox. |
||
| 40 | */ |
||
| 41 | private $oldMessages; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @return string Name of the mailbox. |
||
| 45 | */ |
||
| 46 | public function getName() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return int Count of new messages in the mailbox. |
||
| 53 | */ |
||
| 54 | public function getNewMessages() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return int Count of old messages in the mailbox. |
||
| 61 | */ |
||
| 62 | public function getOldMessages() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param string $response |
||
| 69 | */ |
||
| 70 | public function __construct($response) |
||
| 78 | |||
| 79 | } |
||
| 80 |