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 | class Term extends Abs\Type{ |
||
16 | |||
17 | protected $type = 'term'; |
||
18 | |||
19 | /** |
||
20 | * Create test data posts. |
||
21 | * |
||
22 | * This is where the magic begins. We accept a cpt id (slug) and potntially |
||
23 | * a number of posts to create. We then fetch the supports & metaboxes |
||
24 | * for that cpt and feed them into a function to create each post individually. |
||
25 | * |
||
26 | * @access private |
||
27 | * |
||
28 | * @see $this->get_cpt_supports, $this->get_metaboxes, $this->create_test_object |
||
29 | * |
||
30 | * @param string $slug a custom post type ID. |
||
31 | * @param boolean $echo Whether or not to echo. Optional. |
||
32 | * @param int $num Optional. Number of posts to create. |
||
33 | */ |
||
34 | public function create_objects( $slug, $connection, $echo = false, $num = '' ){ |
||
58 | |||
59 | |||
60 | /** |
||
61 | * Creates the individual test data object. |
||
62 | * |
||
63 | * Create individual posts for testing with. Gathers basic information such |
||
64 | * as title, content, thumbnail, etc. and inserts them with the post. Also |
||
65 | * adds metaboxes if applicable . |
||
66 | * |
||
67 | * @access private |
||
68 | * |
||
69 | * @see TestContent, wp_insert_post, add_post_meta, update_post_meta, $this->random_metabox_content |
||
70 | * |
||
71 | * @param string $slug a custom post type ID. |
||
72 | */ |
||
73 | private function create_test_object( $slug ){ |
||
107 | |||
108 | /** |
||
109 | * Delete test data terms. |
||
110 | * |
||
111 | * This function will search for all terms of a particular taxonomy ($slug) |
||
112 | * and delete them all using a particular term_meta flag that we set when creating |
||
113 | * the posts. Validates the user first. |
||
114 | * |
||
115 | * @see WP_Query, wp_delete_post |
||
116 | * |
||
117 | * @param string $slug a custom post type ID. |
||
118 | * @param boolean $echo Whether or not to echo the result |
||
119 | */ |
||
120 | public function delete( $slug, $echo = false ){ |
||
180 | |||
181 | } |
||
182 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.