Method get_country_locale
has 649 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_country_locale() {
if ( empty( $this->locale ) ) {
$this->locale = apply_filters(
'woocommerce_get_country_locale',
array(
File class-wc-countries.php
has 1147 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* WooCommerce countries
*
* @package WooCommerce\l10n
WC_Countries
has 35 functions (exceeds 20 allowed). Consider refactoring. Open
class WC_Countries {
/**
* Locales list.
*
Method get_default_address_fields
has 87 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_default_address_fields() {
$address_2_label = __( 'Apartment, suite, unit, etc.', 'woocommerce' );
// If necessary, append '(optional)' to the placeholder: we don't need to worry about the
// label, though, as woocommerce_form_field() takes care of that.
Function country_dropdown_options
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public function country_dropdown_options( $selected_country = '', $selected_state = '', $escape = false ) {
if ( $this->countries ) {
foreach ( $this->countries as $key => $value ) {
$states = $this->get_states( $key );
if ( $states ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method get_formatted_address
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_formatted_address( $args = array(), $separator = '<br/>' ) {
$default_args = array(
'first_name' => '',
'last_name' => '',
'company' => '',
Method get_address_formats
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_address_formats() {
if ( empty( $this->address_formats ) ) {
$this->address_formats = apply_filters(
'woocommerce_localisation_address_formats',
array(
Method get_address_fields
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_address_fields( $country = '', $type = 'billing_' ) {
if ( ! $country ) {
$country = $this->get_base_country();
}
Function get_allowed_countries
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function get_allowed_countries() {
if ( 'all' === get_option( 'woocommerce_allowed_countries' ) ) {
return apply_filters( 'woocommerce_countries_allowed_countries', $this->countries );
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get_address_fields
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function get_address_fields( $country = '', $type = 'billing_' ) {
if ( ! $country ) {
$country = $this->get_base_country();
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get_shipping_country_states
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function get_shipping_country_states() {
if ( get_option( 'woocommerce_ship_to_countries' ) === '' ) {
return $this->get_allowed_country_states();
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get_allowed_country_states
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function get_allowed_country_states() {
if ( get_option( 'woocommerce_allowed_countries' ) !== 'specific' ) {
return $this->states;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
$vat_countries = array( 'AE', 'AL', 'AR', 'AZ', 'BB', 'BH', 'BO', 'BS', 'BY', 'CL', 'CO', 'EC', 'EG', 'ET', 'FJ', 'GB', 'GH', 'GM', 'GT', 'IL', 'IM', 'IN', 'IR', 'KN', 'KR', 'KZ', 'LK', 'MC', 'MD', 'ME', 'MK', 'MN', 'MU', 'MX', 'NA', 'NG', 'NO', 'NP', 'PS', 'PY', 'RS', 'RU', 'RW', 'SA', 'SV', 'TH', 'TR', 'UA', 'UY', 'UZ', 'VE', 'VN', 'ZA' );
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 161.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76