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 |
||
| 5 | class mysqlims extends mysqli |
||
|
|
|||
| 6 | { |
||
| 7 | private $mysqliW; |
||
| 8 | private $mysqliR = null; |
||
| 9 | |||
| 10 | /* |
||
| 11 | * Pass main and slave connection arrays to the constructor, and strict as true/false |
||
| 12 | * |
||
| 13 | * @param array $main |
||
| 14 | * @param array $slave |
||
| 15 | * @param boolean $strict |
||
| 16 | * |
||
| 17 | * @return void |
||
| 18 | */ |
||
| 19 | public function __construct($main, $slave = false, $strict = false) |
||
| 51 | |||
| 52 | /* |
||
| 53 | * Override standard mysqli_prepare to select master/slave server |
||
| 54 | * @param $string query |
||
| 55 | * |
||
| 56 | * @return mysqli_stmt |
||
| 57 | */ |
||
| 58 | View Code Duplication | public function prepare($query) |
|
| 66 | |||
| 67 | /* |
||
| 68 | * Override standard mysqli_query to select master/slave server |
||
| 69 | * @param string $query |
||
| 70 | * @param int $resultmode |
||
| 71 | * |
||
| 72 | * @return boolean |
||
| 73 | * @return mixed |
||
| 74 | */ |
||
| 75 | View Code Duplication | public function query($query, $resultmode = MYSQLI_STORE_RESULT) |
|
| 83 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.