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 |
||
| 4 | class CoinAddress extends Base { |
||
| 5 | protected $table = 'coin_addresses'; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * We allow changing the database for shared accounts across pools |
||
| 9 | * Load the config on construct so we can assign the DB name |
||
| 10 | * @param config array MPOS configuration |
||
| 11 | * @return none |
||
|
|
|||
| 12 | **/ |
||
| 13 | public function __construct($config) { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Fetch users coin address for a currency |
||
| 20 | * @param userID int UserID |
||
| 21 | * @return data string Coin Address |
||
| 22 | **/ |
||
| 23 | View Code Duplication | public function getCoinAddress($userID, $currency=NULL) { |
|
| 39 | |||
| 40 | /** |
||
| 41 | * Fetch users Auto Payout Threshold for a currency |
||
| 42 | * @param UserID int UserID |
||
| 43 | * @return mixed Float value for threshold, false on error |
||
| 44 | **/ |
||
| 45 | View Code Duplication | public function getAPThreshold($userID, $currency=NULL) { |
|
| 61 | |||
| 62 | |||
| 63 | /** |
||
| 64 | * Check if a coin address is already set |
||
| 65 | * @param address string Coin Address to check for |
||
| 66 | * @return bool true or false |
||
| 67 | **/ |
||
| 68 | public function existsCoinAddress($address) { |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Add a new coin address record for a user |
||
| 75 | * @param userID int Account ID |
||
| 76 | * @param address string Coin Address |
||
| 77 | * @param currency string Currency short handle, defaults to config option |
||
| 78 | * @return bool true or false |
||
| 79 | **/ |
||
| 80 | public function add($userID, $address, $currency=NULL) { |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Remove a coin address record for a user |
||
| 95 | * @param userID int Account ID |
||
| 96 | * @param currency string Currency short handle, defaults to config option |
||
| 97 | * @return bool true or false |
||
| 98 | **/ |
||
| 99 | public function remove ($userID, $currency=NULL) { |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Update a coin address record for a user and a currency |
||
| 110 | * @param userID int Account ID |
||
| 111 | * @param address string Coin Address |
||
| 112 | * @param ap_threshold float Threshold for auto payouts for this currency |
||
| 113 | * @param currency string Currency short handle, defaults to config option |
||
| 114 | * @return bool true or false |
||
| 115 | **/ |
||
| 116 | public function update($userID, $address, $ap_threshold, $currency=NULL) { |
||
| 135 | } |
||
| 136 | |||
| 141 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.