woothemes/woocommerce

View on GitHub
includes/rest-api/Controllers/Version2/class-wc-rest-setting-options-v2-controller.php

Summary

Maintainability
D
2 days
Test Coverage

File class-wc-rest-setting-options-v2-controller.php has 369 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * REST API Setting Options controller
 *
 * Handles requests to the /settings/$group/$setting endpoints.

    Method get_item_schema has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function get_item_schema() {
            $schema = array(
                '$schema'    => 'http://json-schema.org/draft-04/schema#',
                'title'      => 'setting',
                'type'       => 'object',

      Method register_routes has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function register_routes() {
              register_rest_route(
                  $this->namespace, '/' . $this->rest_base, array(
                      'args'   => array(
                          'group' => array(

        Method get_group_settings has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function get_group_settings( $group_id ) {
                if ( empty( $group_id ) ) {
                    return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
                }
        
        

          Method update_item has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function update_item( $request ) {
                  $setting = $this->get_setting( $request['group_id'], $request['id'] );
          
                  if ( is_wp_error( $setting ) ) {
                      return $setting;

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

                public function get_group_settings( $group_id ) {
                    if ( empty( $group_id ) ) {
                        return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
                    }
            
            

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

                private function get_countries_and_states() {
                    $countries = WC()->countries->get_countries();
                    if ( ! $countries ) {
                        return array();
                    }

            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 $setting;

              Function update_item has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function update_item( $request ) {
                      $setting = $this->get_setting( $request['group_id'], $request['id'] );
              
                      if ( is_wp_error( $setting ) ) {
                          return $setting;

              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 4 locations. Consider refactoring.
              Open

                      register_rest_route(
                          $this->namespace, '/' . $this->rest_base . '/batch', array(
                              'args'   => array(
                                  'group' => array(
                                      'description' => __( 'Settings group ID.', 'woocommerce' ),
              includes/rest-api/Controllers/Version1/class-wc-rest-product-attribute-terms-v1-controller.php on lines 112..126
              includes/rest-api/Controllers/Version2/class-wc-rest-product-reviews-v2-controller.php on lines 41..57
              includes/rest-api/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php on lines 114..130

              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 123.

              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

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                  private function get_countries_and_states() {
                      $countries = WC()->countries->get_countries();
                      if ( ! $countries ) {
                          return array();
                      }
              includes/rest-api/Controllers/Version3/class-wc-rest-setting-options-controller.php on lines 133..151

              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 123.

              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

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                          if ( is_array( $option_key ) ) {
                              $option           = get_option( $option_key[0] );
                              $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default;
                          } else {
                              $admin_setting_value = WC_Admin_Settings::get_option( $option_key, $default );
              includes/rest-api/Controllers/Version3/class-wc-rest-setting-options-controller.php on lines 91..97

              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 96.

              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

              Further Reading

              There are no issues that match your filters.

              Category
              Status