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 |
||
| 11 | class CIPHPUnitTestUnitTestCase extends CIPHPUnitTestCase |
||
|
|
|||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Create a controller instance |
||
| 15 | * |
||
| 16 | * @param string $classname |
||
| 17 | * @return CI_Controller |
||
| 18 | */ |
||
| 19 | public function newController($classname) |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Create a model instance |
||
| 29 | * |
||
| 30 | * @param string $classname |
||
| 31 | * @return CI_Model |
||
| 32 | */ |
||
| 33 | public function newModel($classname) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Create a library instance |
||
| 49 | * |
||
| 50 | * @param string $classname |
||
| 51 | * @param array $args |
||
| 52 | * @return object |
||
| 53 | */ |
||
| 54 | public function newLibrary($classname, $args = null) |
||
| 68 | } |
||
| 69 |
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.