woothemes/woocommerce

View on GitHub
includes/class-wc-geolocation.php

Summary

Maintainability
B
6 hrs
Test Coverage

Function geolocate_via_api has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    private static function geolocate_via_api( $ip_address ) {
        $country_code = get_transient( 'geoip_' . $ip_address );

        if ( false === $country_code ) {
            $geoip_services = apply_filters( 'woocommerce_geolocation_geoip_apis', self::$geoip_apis );
Severity: Minor
Found in includes/class-wc-geolocation.php - About 2 hrs to fix

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 geolocate_ip has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) {
        // Filter to allow custom geolocation of the IP address.
        $country_code = apply_filters( 'woocommerce_geolocate_ip', false, $ip_address, $fallback, $api_fallback );

        if ( false !== $country_code ) {
Severity: Minor
Found in includes/class-wc-geolocation.php - About 1 hr to fix

    Method geolocate_via_api has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static function geolocate_via_api( $ip_address ) {
            $country_code = get_transient( 'geoip_' . $ip_address );
    
            if ( false === $country_code ) {
                $geoip_services = apply_filters( 'woocommerce_geolocation_geoip_apis', self::$geoip_apis );
    Severity: Minor
    Found in includes/class-wc-geolocation.php - About 1 hr to fix

      Function get_external_ip_address has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function get_external_ip_address() {
              $external_ip_address = '0.0.0.0';
      
              if ( '' !== self::get_ip_address() ) {
                  $transient_name      = 'external_ip_address_' . self::get_ip_address();
      Severity: Minor
      Found in includes/class-wc-geolocation.php - About 55 mins to fix

      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 geolocate_ip has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) {
              // Filter to allow custom geolocation of the IP address.
              $country_code = apply_filters( 'woocommerce_geolocate_ip', false, $ip_address, $fallback, $api_fallback );
      
              if ( false !== $country_code ) {
      Severity: Minor
      Found in includes/class-wc-geolocation.php - About 35 mins to fix

      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

      There are no issues that match your filters.

      Category
      Status