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 |
||
13 | class Various extends Abs\View { |
||
14 | |||
15 | public function __construct() { |
||
22 | |||
23 | |||
24 | /** |
||
25 | * Our sections action block - button to create and delete. |
||
26 | * |
||
27 | * @access protected |
||
28 | * |
||
29 | * @return string HTML content. |
||
30 | */ |
||
31 | View Code Duplication | protected function actions_section() { |
|
|
|||
32 | $html = ''; |
||
33 | |||
34 | $html .= "<div class='test-data-cpt'>"; |
||
35 | |||
36 | $html .= "<h3>"; |
||
37 | |||
38 | $html .= "<span class='label'>" . esc_html__( 'Clean Site', 'dummybot' ) . "</span>"; |
||
39 | $html .= $this->build_button( 'delete', 'all', __( 'Delete All Test Data', 'dummybot' ) ); |
||
40 | |||
41 | $html .= "</h3>"; |
||
42 | |||
43 | $html .= "</div>"; |
||
44 | |||
45 | return $html; |
||
46 | } |
||
47 | |||
48 | |||
49 | /** |
||
50 | * We don't need any options on this page, so returning it empty |
||
51 | * |
||
52 | * @access protected |
||
53 | * |
||
54 | * @param string $html Existing HTML content. |
||
55 | * @return string HTML section content. |
||
56 | */ |
||
57 | protected function options_section( $html = '' ) { |
||
60 | |||
61 | } |
||
62 |
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.