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 |
||
27 | abstract class WordPoints_Hook_Event_Dynamic extends WordPoints_Hook_Event { |
||
28 | |||
29 | /** |
||
30 | * The generic portion of the entity slug. |
||
31 | * |
||
32 | * @since 1.0.0 |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $generic_entity_slug; |
||
37 | |||
38 | /** |
||
39 | * Get the title of the entity. |
||
40 | * |
||
41 | * This is useful to interpolate into your event title and description. |
||
42 | * |
||
43 | * @since 1.0.0 |
||
44 | * |
||
45 | * @return string The title of the entity. |
||
46 | */ |
||
47 | protected function get_entity_title() { |
||
65 | } |
||
66 | |||
68 |
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.