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 | private $slave = false; |
||
| 10 | public $lastused = null; |
||
| 11 | |||
| 12 | /* |
||
| 13 | * Pass main and slave connection arrays to the constructor, and strict as true/false |
||
| 14 | * |
||
| 15 | * @param array $main |
||
| 16 | * @param array $slave |
||
| 17 | * @param boolean $strict |
||
| 18 | * |
||
| 19 | * @return void |
||
| 20 | */ |
||
| 21 | public function __construct($main, $slave = false, $strict = false) |
||
| 55 | |||
| 56 | /* |
||
| 57 | * Override standard mysqli_prepare to select master/slave server |
||
| 58 | * @param $string query |
||
| 59 | * |
||
| 60 | * @return mysqli_stmt |
||
| 61 | */ |
||
| 62 | View Code Duplication | public function prepare($query) |
|
| 72 | |||
| 73 | /* |
||
| 74 | * Override standard mysqli_query to select master/slave server |
||
| 75 | * @param string $query |
||
| 76 | * @param int $resultmode |
||
| 77 | * |
||
| 78 | * @return boolean |
||
| 79 | * @return mixed |
||
| 80 | */ |
||
| 81 | View Code Duplication | public function query($query, $resultmode = MYSQLI_STORE_RESULT) |
|
| 91 | } |
||
| 92 |
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.