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 |
||
| 18 | class notifications_email implements notifications_iface { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Appname |
||
| 22 | */ |
||
| 23 | const _appname = 'notifications'; |
||
|
|
|||
| 24 | |||
| 25 | /** |
||
| 26 | * holds account object for user who sends the message |
||
| 27 | * |
||
| 28 | * @var object |
||
| 29 | */ |
||
| 30 | private $sender; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * holds account object for user to notify |
||
| 34 | * |
||
| 35 | * @var object |
||
| 36 | */ |
||
| 37 | private $recipient; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * holds config object (sitewide application config) |
||
| 41 | * |
||
| 42 | * @var object |
||
| 43 | */ |
||
| 44 | private $config; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * holds preferences object of user to notify |
||
| 48 | * |
||
| 49 | * @var Api\Preferences |
||
| 50 | */ |
||
| 51 | private $preferences; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * holds mail object |
||
| 55 | * |
||
| 56 | * @var send |
||
| 57 | */ |
||
| 58 | private $mail; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * constructor of notifications_email |
||
| 62 | * |
||
| 63 | * @param object $_sender |
||
| 64 | * @param object $_recipient |
||
| 65 | * @param object $_config |
||
| 66 | * @param object $_preferences |
||
| 67 | */ |
||
| 68 | public function __construct($_sender, $_recipient, $_config = null, $_preferences = null) { |
||
| 81 | |||
| 82 | /** |
||
| 83 | * sends notification |
||
| 84 | * |
||
| 85 | * @param array $_messages |
||
| 86 | * @param string $_subject |
||
| 87 | * @param array $_links |
||
| 88 | * @param array $_attachments |
||
| 89 | */ |
||
| 90 | public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * renders plaintext/html links from given link array |
||
| 135 | * |
||
| 136 | * @param array $_links |
||
| 137 | * @param boolean $_render_html |
||
| 138 | * @param boolean $_render_external |
||
| 139 | * @return plain or html rendered link(s) as complete string |
||
| 140 | */ |
||
| 141 | private function render_links($_links = false, $_render_html = false, $_render_external = true) { |
||
| 167 | |||
| 168 | } |
||
| 169 |