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 |
||
| 15 | View Code Duplication | class WordPoints_BP_Entity_Message extends WordPoints_BP_Entity { |
|
|
|
|||
| 16 | |||
| 17 | /** |
||
| 18 | * @since 1.0.0 |
||
| 19 | */ |
||
| 20 | protected $bp_component = 'messages'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @since 1.0.0 |
||
| 24 | */ |
||
| 25 | protected $bp_component_table_name = 'messages'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @since 1.0.0 |
||
| 29 | */ |
||
| 30 | protected $id_field = 'id'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @since 1.2.1 |
||
| 34 | */ |
||
| 35 | protected $id_is_int = true; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @since 1.0.0 |
||
| 39 | */ |
||
| 40 | protected $human_id_field = 'subject'; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @since 1.0.0 |
||
| 44 | */ |
||
| 45 | protected function get_entity( $id ) { |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @since 1.0.0 |
||
| 58 | */ |
||
| 59 | public function get_title() { |
||
| 62 | } |
||
| 63 | |||
| 65 |
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.