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 | abstract class WordPoints_Entity_Attr_Field |
||
16 | extends WordPoints_Entity_Attr |
||
17 | implements WordPoints_Entityish_StoredI { |
||
18 | |||
19 | /** |
||
20 | * The storage type for this entity attribute. |
||
21 | * |
||
22 | * @since 1.0.0 |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $storage_type; |
||
27 | |||
28 | /** |
||
29 | * The field that this attribute is stored in on the entity. |
||
30 | * |
||
31 | * @since 1.0.0 |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $field; |
||
36 | |||
37 | /** |
||
38 | * @since 1.0.0 |
||
39 | */ |
||
40 | protected function get_attr_value_from_entity( WordPoints_Entity $entity ) { |
||
43 | |||
44 | /** |
||
45 | * @since 1.0.0 |
||
46 | */ |
||
47 | View Code Duplication | public function get_storage_info() { |
|
56 | } |
||
57 | |||
59 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.