| Total Complexity | 95 |
| Total Lines | 468 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
Complex classes like WPInv_EUVat 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 WPInv_EUVat, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class WPInv_EUVat { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Retrieves an instance of this class. |
||
| 13 | * |
||
| 14 | * @deprecated |
||
| 15 | * @return WPInv_EUVat |
||
| 16 | */ |
||
| 17 | public static function get_instance() { |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @deprecated |
||
| 23 | */ |
||
| 24 | public function init() {} |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @deprecated |
||
| 28 | */ |
||
| 29 | public static function section_vat_settings() {} |
||
| 30 | |||
| 31 | public static function get_eu_states( $sort = true ) { |
||
| 32 | $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' ); |
||
| 33 | if ( $sort ) { |
||
| 34 | $sort = sort( $eu_states ); |
||
| 35 | } |
||
| 36 | |||
| 37 | return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort ); |
||
| 38 | } |
||
| 39 | |||
| 40 | public static function get_gst_countries( $sort = true ) { |
||
| 41 | $gst_countries = array( 'AU', 'NZ', 'CA', 'CN' ); |
||
| 42 | |||
| 43 | if ( $sort ) { |
||
| 44 | $sort = sort( $gst_countries ); |
||
| 45 | } |
||
| 46 | |||
| 47 | return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort ); |
||
| 48 | } |
||
| 49 | |||
| 50 | public static function is_eu_state( $country_code ) { |
||
| 51 | $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false; |
||
| 52 | |||
| 53 | return apply_filters( 'wpinv_is_eu_state', $return, $country_code ); |
||
| 54 | } |
||
| 55 | |||
| 56 | public static function is_gst_country( $country_code ) { |
||
| 57 | $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false; |
||
| 58 | |||
| 59 | return apply_filters( 'wpinv_is_gst_country', $return, $country_code ); |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @deprecated |
||
| 64 | */ |
||
| 65 | public function enqueue_vat_scripts() {} |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @deprecated |
||
| 69 | */ |
||
| 70 | public function load_vat_scripts(){} |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @deprecated |
||
| 74 | */ |
||
| 75 | public static function enqueue_admin_scripts() {} |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @deprecated |
||
| 79 | */ |
||
| 80 | public static function vat_rates_settings() {} |
||
| 81 | |||
| 82 | /** |
||
| 83 | * |
||
| 84 | * @deprecated |
||
| 85 | */ |
||
| 86 | public static function vat_settings() {} |
||
| 87 | |||
| 88 | /** |
||
| 89 | * |
||
| 90 | * @deprecated |
||
| 91 | */ |
||
| 92 | public static function maxmind_folder() { |
||
| 93 | return false; |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * |
||
| 98 | * @deprecated |
||
| 99 | */ |
||
| 100 | public static function geoip2_download_database() {} |
||
| 101 | |||
| 102 | /** |
||
| 103 | * |
||
| 104 | * @deprecated |
||
| 105 | */ |
||
| 106 | public static function geoip2_download_file() {} |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @deprecated |
||
| 110 | */ |
||
| 111 | public static function load_geoip2() {} |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @deprecated |
||
| 115 | */ |
||
| 116 | public static function geoip2_country_dbfile() { |
||
| 117 | return false; |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @deprecated |
||
| 122 | */ |
||
| 123 | public static function geoip2_city_dbfile() { |
||
| 124 | return false; |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @deprecated |
||
| 129 | */ |
||
| 130 | public static function geoip2_country_reader() { |
||
| 131 | return false; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @deprecated |
||
| 136 | */ |
||
| 137 | public static function geoip2_city_reader() { |
||
| 138 | return false; |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @deprecated |
||
| 143 | */ |
||
| 144 | public static function geoip2_country_record() { |
||
| 145 | return false; |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @deprecated |
||
| 150 | */ |
||
| 151 | public static function geoip2_city_record() { |
||
| 152 | return false; |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @deprecated |
||
| 157 | */ |
||
| 158 | public static function geoip2_country_code() { |
||
| 159 | wpinv_get_default_country(); |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @deprecated |
||
| 164 | */ |
||
| 165 | public static function get_country_by_ip() { |
||
| 166 | return getpaid_get_ip_country(); |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @deprecated |
||
| 171 | */ |
||
| 172 | public static function sanitize_vat_settings() {} |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @deprecated |
||
| 176 | */ |
||
| 177 | public static function sanitize_vat_rates() {} |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @deprecated |
||
| 181 | */ |
||
| 182 | public static function add_class() {} |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @deprecated |
||
| 186 | */ |
||
| 187 | public static function delete_class() {} |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @deprecated |
||
| 191 | */ |
||
| 192 | public static function update_eu_rates() {} |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @deprecated |
||
| 196 | */ |
||
| 197 | public static function hide_vat_fields() {} |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @deprecated |
||
| 201 | */ |
||
| 202 | public static function same_country_rule() { |
||
| 203 | return wpinv_same_country_exempt_vat(); |
||
| 204 | } |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Retrieves the vat name. |
||
| 208 | */ |
||
| 209 | public function get_vat_name() { |
||
| 210 | $vat_name = wpinv_get_option( 'vat_name' ); |
||
| 211 | return empty( $vat_name ) ? __( 'VAT', 'invoicing' ) : sanitize_text_field( $vat_name ); |
||
| 212 | } |
||
| 213 | |||
| 214 | public static function get_company_name() { |
||
| 218 | } |
||
| 219 | |||
| 220 | public static function get_vat_number() { |
||
| 221 | $vat_number = wpinv_get_option( 'vat_number' ); |
||
| 222 | |||
| 223 | return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
||
| 224 | } |
||
| 225 | |||
| 226 | public static function is_vat_validated() { |
||
| 227 | $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
||
| 228 | |||
| 229 | return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
||
| 230 | } |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @deprecated |
||
| 234 | */ |
||
| 235 | public static function sanitize_vat() {} |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @deprecated |
||
| 239 | */ |
||
| 240 | public static function offline_check( $vat_number ) { |
||
| 241 | return wpinv_regex_validate_vat_number( $vat_number ); |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @deprecated |
||
| 246 | */ |
||
| 247 | public static function vies_check() {} |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @deprecated |
||
| 251 | */ |
||
| 252 | public static function check_vat() {} |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @deprecated |
||
| 256 | */ |
||
| 257 | public static function request_euvatrates() { |
||
| 258 | return array(); |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @deprecated |
||
| 263 | */ |
||
| 264 | public static function requires_vat() {} |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @deprecated |
||
| 268 | */ |
||
| 269 | public static function tax_label() {} |
||
| 270 | |||
| 271 | public static function standard_rates_label() { |
||
| 272 | return __( 'Standard Rates', 'invoicing' ); |
||
| 273 | } |
||
| 274 | |||
| 275 | public static function get_rate_classes( $with_desc = false ) { |
||
| 276 | $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
||
| 277 | $classes = maybe_unserialize( $rate_classes_option ); |
||
| 278 | |||
| 279 | if ( empty( $classes ) || !is_array( $classes ) ) { |
||
| 280 | $classes = array(); |
||
| 281 | } |
||
| 282 | |||
| 283 | $rate_classes = array(); |
||
| 284 | if ( !array_key_exists( '_standard', $classes ) ) { |
||
| 285 | if ( $with_desc ) { |
||
| 286 | $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
||
| 287 | } else { |
||
| 288 | $rate_classes['_standard'] = self::standard_rates_label(); |
||
| 289 | } |
||
| 290 | } |
||
| 291 | |||
| 292 | foreach ( $classes as $key => $class ) { |
||
| 293 | $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
||
| 294 | $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
||
| 295 | |||
| 296 | if ( $with_desc ) { |
||
| 297 | $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
||
| 298 | } else { |
||
| 299 | $rate_classes[$key] = $name; |
||
| 300 | } |
||
| 301 | } |
||
| 302 | |||
| 303 | return $rate_classes; |
||
| 304 | } |
||
| 305 | |||
| 306 | public static function get_all_classes() { |
||
| 307 | $classes = self::get_rate_classes(); |
||
| 308 | $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
||
| 309 | |||
| 310 | return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
||
| 311 | } |
||
| 312 | |||
| 313 | public static function get_class_desc( $rate_class ) { |
||
| 314 | $rate_classes = self::get_rate_classes( true ); |
||
| 315 | |||
| 316 | if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
||
| 317 | return $rate_classes[$rate_class]['desc']; |
||
| 318 | } |
||
| 319 | |||
| 320 | return ''; |
||
| 321 | } |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @deprecated |
||
| 325 | */ |
||
| 326 | public static function get_vat_groups() {} |
||
| 327 | |||
| 328 | public static function get_rules() { |
||
| 329 | $vat_rules = array( |
||
| 330 | 'digital' => __( 'Digital Product', 'invoicing' ), |
||
| 331 | 'physical' => __( 'Physical Product', 'invoicing' ), |
||
| 332 | '_exempt' => __( 'Tax-Free Product', 'invoicing' ), |
||
| 333 | ); |
||
| 334 | return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
||
| 335 | } |
||
| 336 | |||
| 337 | public static function get_vat_rates( $class ) { |
||
| 338 | if ( $class === '_standard' ) { |
||
| 339 | return GetPaid_Tax::get_all_tax_rates(); |
||
| 340 | } |
||
| 341 | |||
| 342 | $rates = self::get_non_standard_rates(); |
||
| 343 | |||
| 344 | return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
||
| 345 | } |
||
| 346 | |||
| 347 | public static function get_non_standard_rates() { |
||
| 348 | $option = get_option( 'wpinv_vat_rates', array()); |
||
| 349 | return is_array( $option ) ? $option : array(); |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @deprecated |
||
| 354 | */ |
||
| 355 | public static function allow_vat_rules() { |
||
| 356 | return wpinv_use_taxes(); |
||
| 357 | } |
||
| 358 | |||
| 359 | /** |
||
| 360 | * @deprecated |
||
| 361 | */ |
||
| 362 | public static function allow_vat_classes() { |
||
| 363 | return wpinv_use_taxes(); |
||
| 364 | } |
||
| 365 | |||
| 366 | public static function get_item_class( $postID ) { |
||
| 367 | $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
||
| 368 | |||
| 369 | if ( empty( $class ) ) { |
||
| 370 | $class = '_standard'; |
||
| 371 | } |
||
| 372 | |||
| 373 | return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
||
| 374 | } |
||
| 375 | |||
| 376 | public static function item_class_label( $postID ) { |
||
| 377 | $vat_classes = self::get_all_classes(); |
||
| 378 | |||
| 379 | $class = self::get_item_class( $postID ); |
||
| 380 | $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
||
| 381 | |||
| 382 | return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
||
| 383 | } |
||
| 384 | |||
| 385 | public static function get_item_rule( $postID ) { |
||
| 386 | $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
||
| 387 | |||
| 388 | if ( empty( $rule_type ) ) { |
||
| 389 | $rule_type = 'digital'; |
||
| 390 | } |
||
| 391 | |||
| 392 | return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
||
| 393 | } |
||
| 394 | |||
| 395 | public static function item_rule_label( $postID ) { |
||
| 396 | $vat_rules = self::get_rules(); |
||
| 397 | $vat_rule = self::get_item_rule( $postID ); |
||
| 398 | $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
||
| 399 | |||
| 400 | return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
||
| 401 | } |
||
| 402 | |||
| 403 | /** |
||
| 404 | * @deprecated |
||
| 405 | */ |
||
| 406 | public static function item_has_digital_rule() { |
||
| 407 | return true; |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @deprecated |
||
| 412 | */ |
||
| 413 | public static function invoice_has_digital_rule() { |
||
| 414 | return false; |
||
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @deprecated |
||
| 419 | */ |
||
| 420 | public static function item_is_taxable() { |
||
| 421 | return true; |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @deprecated |
||
| 426 | */ |
||
| 427 | public static function find_rate() { |
||
| 429 | } |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @deprecated |
||
| 433 | */ |
||
| 434 | public static function get_rate() { |
||
| 435 | return 0; |
||
| 436 | } |
||
| 437 | |||
| 438 | /** |
||
| 439 | * @deprecated |
||
| 440 | */ |
||
| 441 | public static function current_vat_data() {} |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @deprecated |
||
| 445 | */ |
||
| 446 | public static function get_user_country() {} |
||
| 447 | |||
| 448 | /** |
||
| 449 | * @deprecated |
||
| 450 | */ |
||
| 451 | public static function set_user_country() {} |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @deprecated |
||
| 455 | */ |
||
| 456 | public static function get_user_vat_number() {} |
||
| 457 | |||
| 458 | /** |
||
| 459 | * @deprecated |
||
| 460 | */ |
||
| 461 | public static function get_user_company() {} |
||
| 462 | |||
| 463 | /** |
||
| 464 | * @deprecated |
||
| 465 | */ |
||
| 466 | public static function save_user_vat_details() {} |
||
| 467 | |||
| 468 | /** |
||
| 469 | * @deprecated |
||
| 470 | */ |
||
| 471 | public static function ajax_vat_validate() {} |
||
| 472 | |||
| 473 | /** |
||
| 474 | * @deprecated |
||
| 475 | */ |
||
| 476 | public static function validate_vat_number() {} |
||
| 477 | |||
| 478 | } |
||
| 479 | |||
| 480 |