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 |
||
| 6 | class Analysis_Background_Service { |
||
| 7 | |||
| 8 | |||
| 9 | const ANALYSIS_DONE_FLAG = '_wl_cmkg_analysis_complete_for_term_options_cache'; |
||
| 10 | const TERMS_COUNT_TRANSIENT = '_wl_cmkg_analysis_background_service_terms_count'; |
||
| 11 | const ENTITIES_PRESENT_FOR_TERM = '_wl_cmkg_analysis_entities_present_for_term_options_cache'; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var Analysis_Service |
||
| 15 | */ |
||
| 16 | private $analysis_service; |
||
| 17 | /** |
||
| 18 | * @var Analysis_Background_Process |
||
| 19 | */ |
||
| 20 | private $analysis_background_process; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var \Wordlift_Log_Service |
||
| 24 | */ |
||
| 25 | private $log; |
||
| 26 | |||
| 27 | |||
| 28 | public function __construct( $analysis_service ) { |
||
| 36 | |||
| 37 | public function start() { |
||
| 40 | |||
| 41 | public function cancel() { |
||
| 44 | |||
| 45 | public function stop() { |
||
| 49 | |||
| 50 | /** |
||
| 51 | * A list of term ids. |
||
| 52 | * @return int|\WP_Error|\WP_Term[] |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function next() { |
|
| 72 | |||
| 73 | View Code Duplication | public function count() { |
|
| 94 | |||
| 95 | public function get_batch_size() { |
||
| 98 | |||
| 99 | public function info() { |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param $term_ids |
||
| 105 | * |
||
| 106 | * @return bool |
||
| 107 | */ |
||
| 108 | public function perform_analysis_for_terms( $term_ids ) { |
||
| 139 | |||
| 140 | } |
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.