woothemes/woocommerce

View on GitHub
includes/gateways/cod/class-wc-gateway-cod.php

Summary

Maintainability
C
1 day
Test Coverage

Function is_available has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    public function is_available() {
        $order          = null;
        $needs_shipping = false;

        // Test if shipping is needed first.
Severity: Minor
Found in includes/gateways/cod/class-wc-gateway-cod.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 init_form_fields has 49 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function init_form_fields() {
        $this->form_fields = array(
            'enabled'            => array(
                'title'       => __( 'Enable/Disable', 'woocommerce' ),
                'label'       => __( 'Enable cash on delivery', 'woocommerce' ),
Severity: Minor
Found in includes/gateways/cod/class-wc-gateway-cod.php - About 1 hr to fix

    Function load_shipping_method_options has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        private function load_shipping_method_options() {
            // Since this is expensive, we only want to do it if we're actually on the settings page.
            if ( ! $this->is_accessing_settings() ) {
                return array();
            }
    Severity: Minor
    Found in includes/gateways/cod/class-wc-gateway-cod.php - About 1 hr 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 is_accessing_settings has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        private function is_accessing_settings() {
            if ( is_admin() ) {
                // phpcs:disable WordPress.Security.NonceVerification
                if ( ! isset( $_REQUEST['page'] ) || 'wc-settings' !== $_REQUEST['page'] ) {
                    return false;
    Severity: Minor
    Found in includes/gateways/cod/class-wc-gateway-cod.php - About 1 hr 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 is_available has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function is_available() {
            $order          = null;
            $needs_shipping = false;
    
            // Test if shipping is needed first.
    Severity: Minor
    Found in includes/gateways/cod/class-wc-gateway-cod.php - About 1 hr to fix

      Method load_shipping_method_options has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function load_shipping_method_options() {
              // Since this is expensive, we only want to do it if we're actually on the settings page.
              if ( ! $this->is_accessing_settings() ) {
                  return array();
              }
      Severity: Minor
      Found in includes/gateways/cod/class-wc-gateway-cod.php - About 1 hr to fix

        Function get_canonical_package_rate_ids has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            private function get_canonical_package_rate_ids( $chosen_package_rate_ids ) {
        
                $shipping_packages  = WC()->shipping()->get_packages();
                $canonical_rate_ids = array();
        
        
        Severity: Minor
        Found in includes/gateways/cod/class-wc-gateway-cod.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

        Avoid too many return statements within this method.
        Open

                        return true;
        Severity: Major
        Found in includes/gateways/cod/class-wc-gateway-cod.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return false;
          Severity: Major
          Found in includes/gateways/cod/class-wc-gateway-cod.php - About 30 mins to fix

            There are no issues that match your filters.

            Category
            Status