Complex classes like WETU_Importer_Admin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WETU_Importer_Admin, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class WETU_Importer_Admin extends WETU_Importer { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * The previously attached images |
||
| 14 | * |
||
| 15 | * @var array() |
||
| 16 | */ |
||
| 17 | public $found_attachments = array(); |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The gallery ids for the found attachements |
||
| 21 | * |
||
| 22 | * @var array() |
||
| 23 | */ |
||
| 24 | public $gallery_meta = array(); |
||
| 25 | |||
| 26 | /** |
||
| 27 | * the featured image id |
||
| 28 | * |
||
| 29 | * @var int |
||
| 30 | */ |
||
| 31 | public $featured_image = false; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * the banner image |
||
| 35 | * |
||
| 36 | * @var int |
||
| 37 | */ |
||
| 38 | public $banner_image = false; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Initialize the plugin by setting localization, filters, and administration functions. |
||
| 42 | * |
||
| 43 | * @since 1.0.0 |
||
| 44 | * |
||
| 45 | * @access private |
||
| 46 | */ |
||
| 47 | public function __construct() { |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Registers the admin page which will house the importer form. |
||
| 54 | */ |
||
| 55 | public function register_importer_page() { |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Enqueue the JS needed to contact wetu and return your result. |
||
| 61 | */ |
||
| 62 | public function admin_scripts() { |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Display the importer administration screen |
||
| 79 | */ |
||
| 80 | public function display_page() { |
||
| 108 | |||
| 109 | /** |
||
| 110 | * The header of the item list |
||
| 111 | */ |
||
| 112 | public function table_header() { |
||
| 127 | |||
| 128 | /** |
||
| 129 | * The footer of the item list |
||
| 130 | */ |
||
| 131 | public function table_footer() { |
||
| 146 | |||
| 147 | /** |
||
| 148 | * set_taxonomy with some terms |
||
| 149 | */ |
||
| 150 | public function set_taxonomy($taxonomy,$terms,$id) { |
||
| 183 | |||
| 184 | /** |
||
| 185 | * set_taxonomy with some terms |
||
| 186 | */ |
||
| 187 | public function team_member_checkboxes($selected=array()) { |
||
| 188 | if(post_type_exists('team')) { ?> |
||
| 189 | <ul> |
||
| 190 | <?php |
||
| 191 | $team_args=array( |
||
| 192 | 'post_type' => 'team', |
||
| 193 | 'post_status' => 'publish', |
||
| 194 | 'nopagin' => true, |
||
| 195 | 'fields' => 'ids' |
||
| 196 | ); |
||
| 197 | $team_members = new WP_Query($team_args); |
||
| 198 | if($team_members->have_posts()){ |
||
| 199 | foreach($team_members->posts as $member){ ?> |
||
| 200 | <li><input class="team" checked="<?php $this->checked($selected,$member); ?>" type="checkbox" value="<?php echo $member; ?>" /> <?php echo get_the_title($member); ?></li> |
||
| 201 | <?php } |
||
| 202 | }else{ ?> |
||
| 203 | <li><input class="team" type="checkbox" value="0" /> <?php _e('None','wetu-importer'); ?></li> |
||
| 204 | <?php } |
||
| 205 | ?> |
||
| 206 | </ul> |
||
| 207 | <?php } |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * set_taxonomy with some terms |
||
| 212 | */ |
||
| 213 | public function taxonomy_checkboxes($taxonomy=false) { |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Saves the room data |
||
| 232 | */ |
||
| 233 | public function save_custom_field($value=false,$meta_key,$id,$decrease=false,$unique=true) { |
||
| 248 | |||
| 249 | /** |
||
| 250 | * grabs any attachments for the current item |
||
| 251 | */ |
||
| 252 | public function find_attachments($id=false) { |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Checks to see if an item is selected. |
||
| 276 | * |
||
| 277 | * @param $haystack array|string |
||
| 278 | * @param $needle string |
||
| 279 | * @return string |
||
| 280 | */ |
||
| 281 | public function checked($haystack=false,$needle='') { |
||
| 291 | } |
||
| 292 | $wetu_importer_admin = new WETU_Importer_Admin(); |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.