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 |
||
22 | class ALNP_Twenty_Twelve { |
||
23 | |||
24 | /** |
||
25 | * Initlize Theme. |
||
26 | * |
||
27 | * @access public |
||
28 | * @static |
||
29 | */ |
||
30 | View Code Duplication | public static function init() { |
|
40 | |||
41 | /** |
||
42 | * Adds a compaitable post navigation. |
||
43 | * |
||
44 | * @access public |
||
45 | * @static |
||
46 | */ |
||
47 | public static function alnp_twentytwelve_post_navigation() { |
||
55 | |||
56 | /** |
||
57 | * Add theme support by providing the theme selectors |
||
58 | * to be applied once the theme is activated. |
||
59 | * |
||
60 | * @access public |
||
61 | * @static |
||
62 | */ |
||
63 | public static function add_theme_support() { |
||
71 | |||
72 | } // END class |
||
73 | |||
75 |
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.