| Total Complexity | 40 | 
| Total Lines | 240 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
Complex classes like LSX_TO_Team 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.
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 LSX_TO_Team, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 20 | 	class LSX_TO_Team { | ||
| 21 | |||
| 22 | /** | ||
| 23 | * The plugins id | ||
| 24 | */ | ||
| 25 | public $plugin_slug = 'to-team'; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * The post types the plugin registers | ||
| 29 | */ | ||
| 30 | public $post_types = false; | ||
| 31 | |||
| 32 | /** | ||
| 33 | * The singular post types the plugin registers | ||
| 34 | */ | ||
| 35 | public $post_types_singular = false; | ||
| 36 | |||
| 37 | /** | ||
| 38 | * An array of the post types slugs plugin registers | ||
| 39 | */ | ||
| 40 | public $post_type_slugs = false; | ||
| 41 | |||
| 42 | /** | ||
| 43 | * The taxonomies the plugin registers | ||
| 44 | */ | ||
| 45 | public $taxonomies = false; | ||
| 46 | |||
| 47 | /** | ||
| 48 | * The taxonomies the plugin registers (plural) | ||
| 49 | */ | ||
| 50 | public $taxonomies_plural = false; | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Site users | ||
| 54 | */ | ||
| 55 | public $site_users = array(); | ||
| 56 | |||
| 57 | /** | ||
| 58 | * Constructor | ||
| 59 | */ | ||
| 60 | 		public function __construct() { | ||
| 89 | } | ||
| 90 | |||
| 91 | /** | ||
| 92 | * Include the post type for the search integration | ||
| 93 | */ | ||
| 94 | 		public function lsx_to_search_integration() { | ||
| 97 | } | ||
| 98 | |||
| 99 | /** | ||
| 100 | * Load the plugin text domain for translation. | ||
| 101 | */ | ||
| 102 | 		public function load_plugin_textdomain() { | ||
| 104 | } | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Sets the plugins variables | ||
| 108 | */ | ||
| 109 | 		public function set_vars() { | ||
| 110 | $this->post_types = array( | ||
| 111 | 'team' => __( 'Team', 'to-team' ), | ||
| 112 | ); | ||
| 113 | |||
| 114 | $this->post_types_singular = array( | ||
| 115 | 'team' => __( 'Team Member', 'to-team' ), | ||
| 116 | ); | ||
| 117 | |||
| 118 | $this->post_type_slugs = array_keys( $this->post_types ); | ||
| 119 | |||
| 120 | $users = get_users(); | ||
| 121 | |||
| 122 | 			foreach ( $users as $user ) { | ||
| 123 | $this->site_users[] = array( | ||
| 124 | 'name' => $user->display_name, | ||
| 125 | 'value' => $user->ID, | ||
| 126 | ); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Adds our post types to an array via a filter | ||
| 132 | */ | ||
| 133 | 		public function plugin_path( $path, $post_type ) { | ||
| 134 | 			if ( false !== $this->post_types && array_key_exists( $post_type, $this->post_types ) ) { | ||
| 135 | $path = LSX_TO_TEAM_PATH; | ||
| 136 | } | ||
| 137 | |||
| 138 | return $path; | ||
| 139 | } | ||
| 140 | |||
| 141 | /** | ||
| 142 | * Adds our post types to an array via a filter | ||
| 143 | */ | ||
| 144 | 		public function post_types_slugs_filter( $post_types ) { | ||
| 145 | 			if ( is_array( $post_types ) ) { | ||
| 146 | $post_types = array_merge( $post_types, $this->post_type_slugs ); | ||
| 147 | 			} else { | ||
| 148 | $post_types = $this->post_type_slugs; | ||
| 149 | } | ||
| 150 | |||
| 151 | return $post_types; | ||
| 152 | } | ||
| 153 | |||
| 154 | /** | ||
| 155 | * Adds our post types to an array via a filter | ||
| 156 | */ | ||
| 157 | 		public function post_types_filter( $post_types ) { | ||
| 158 | 			if ( is_array( $post_types ) && is_array( $this->post_types ) ) { | ||
| 159 | $post_types = array_merge( $post_types, $this->post_types ); | ||
| 160 | 			} elseif ( is_array( $this->post_types ) ) { | ||
| 161 | $post_types = $this->post_types; | ||
| 162 | } | ||
| 163 | |||
| 164 | return $post_types; | ||
| 165 | } | ||
| 166 | |||
| 167 | /** | ||
| 168 | * Adds our post types to an array via a filter | ||
| 169 | */ | ||
| 170 | 		public function post_types_singular_filter( $post_types_singular ) { | ||
| 171 | 			if ( is_array( $post_types_singular ) && is_array( $this->post_types_singular ) ) { | ||
| 172 | $post_types_singular = array_merge( $post_types_singular, $this->post_types_singular ); | ||
| 173 | 			} elseif ( is_array( $this->post_types_singular ) ) { | ||
| 174 | $post_types_singular = $this->post_types_singular; | ||
| 175 | } | ||
| 176 | |||
| 177 | return $post_types_singular; | ||
| 178 | } | ||
| 179 | |||
| 180 | /** | ||
| 181 | * Adds our taxonomies to an array via a filter | ||
| 182 | */ | ||
| 183 | 		public function taxonomies_filter( $taxonomies ) { | ||
| 184 | 			if ( is_array( $taxonomies ) && is_array( $this->taxonomies ) ) { | ||
| 185 | $taxonomies = array_merge( $taxonomies, $this->taxonomies ); | ||
| 186 | 			} elseif ( is_array( $this->taxonomies ) ) { | ||
| 187 | $taxonomies = $this->taxonomies; | ||
| 188 | } | ||
| 189 | |||
| 190 | return $taxonomies; | ||
| 191 | } | ||
| 192 | |||
| 193 | /** | ||
| 194 | * Adds our taxonomies_plural to an array via a filter | ||
| 195 | */ | ||
| 196 | 		public function taxonomies_plural_filter( $taxonomies_plural ) { | ||
| 197 | 			if ( is_array( $taxonomies_plural ) && is_array( $this->taxonomies_plural ) ) { | ||
| 198 | $taxonomies_plural = array_merge( $taxonomies_plural, $this->taxonomies_plural ); | ||
| 199 | 			} elseif ( is_array( $this->taxonomies_plural ) ) { | ||
| 200 | $taxonomies_plural = $this->taxonomies_plural; | ||
| 201 | } | ||
| 202 | |||
| 203 | return $taxonomies_plural; | ||
| 204 | } | ||
| 205 | |||
| 206 | /** | ||
| 207 | * Make TO last plugin to load. | ||
| 208 | */ | ||
| 209 | 		public function activated_plugin() { | ||
| 210 | // @codingStandardsIgnoreLine | ||
| 211 | 			if ( $plugins = get_option( 'active_plugins' ) ) { | ||
| 212 | $search = preg_grep( '/.*\/tour-operator\.php/', $plugins ); | ||
| 213 | $key = array_search( $search, $plugins ); | ||
| 214 | |||
| 215 | 				if ( is_array( $search ) && count( $search ) ) { | ||
| 216 | 					foreach ( $search as $key => $path ) { | ||
| 217 | array_splice( $plugins, $key, 1 ); | ||
| 218 | array_push( $plugins, $path ); | ||
| 219 | update_option( 'active_plugins', $plugins ); | ||
| 220 | } | ||
| 221 | } | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 225 | /** | ||
| 226 | * On plugin activation | ||
| 227 | */ | ||
| 228 | 		public function register_activation_hook() { | ||
| 229 | 			if ( ! is_network_admin() && ! isset( $_GET['activate-multi'] ) ) { | ||
| 230 | set_transient( '_tour_operators_team_flush_rewrite_rules', 1, 30 ); | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | /** | ||
| 235 | * On plugin activation (check) | ||
| 236 | */ | ||
| 237 | 		public function register_activation_hook_check() { | ||
| 244 | } | ||
| 245 | |||
| 246 | /** | ||
| 247 | * Adds Schema pieces to our output. | ||
| 248 | * | ||
| 249 | * @param array $pieces Graph pieces to output. | ||
| 250 | * @param \WPSEO_Schema_Context $context Object with context variables. | ||
| 251 | * | ||
| 252 | * @return array $pieces Graph pieces to output. | ||
| 253 | */ | ||
| 254 | 		public function add_graph_pieces( $pieces, $context ) { | ||
| 260 | } | ||
| 261 | } | ||
| 262 | |||
| 263 | global $lsx_to_team; | ||
| 264 | $lsx_to_team = new LSX_TO_Team(); | ||
| 265 | |||
| 266 | } | ||
| 267 |