woothemes/woocommerce

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

Summary

Maintainability
F
1 wk
Test Coverage

File class-wc-rest-system-status-v2-controller.php has 994 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * REST API WC System Status controller
 *
 * Handles requests to the /system_status endpoint.

    Method get_item_schema has 469 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'      => 'system_status',
                'type'       => 'object',

      Function get_theme_info has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          public function get_theme_info() {
              $active_theme = wp_get_theme();
      
              // Get parent theme info if this theme is a child theme, otherwise
              // pass empty info in the response.

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

          public function get_environment_info_per_fields( $fields ) {
              global $wpdb;
      
              $enable_remote_post = $this->check_if_field_item_exists( 'environment', array( 'remote_post_successful', 'remote_post_response' ), $fields );
              $enable_remote_get  = $this->check_if_field_item_exists( 'environment', array( 'remote_get_successful', 'remote_get_response' ), $fields );

        Method get_pages has 72 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function get_pages() {
                // WC pages to check against.
                $check_pages = array(
                    _x( 'Shop base', 'Page setting', 'woocommerce' ) => array(
                        'option'    => 'woocommerce_shop_page_id',

          Method get_theme_info has 69 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function get_theme_info() {
                  $active_theme = wp_get_theme();
          
                  // Get parent theme info if this theme is a child theme, otherwise
                  // pass empty info in the response.

            Function get_environment_info_per_fields has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

                public function get_environment_info_per_fields( $fields ) {
                    global $wpdb;
            
                    $enable_remote_post = $this->check_if_field_item_exists( 'environment', array( 'remote_post_successful', 'remote_post_response' ), $fields );
                    $enable_remote_get  = $this->check_if_field_item_exists( 'environment', array( 'remote_get_successful', 'remote_get_response' ), $fields );

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

                public function get_database_info() {
                    global $wpdb;
            
                    $tables        = array();
                    $database_size = array();

              WC_REST_System_Status_V2_Controller has 22 functions (exceeds 20 allowed). Consider refactoring.
              Open

              class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
              
                  /**
                   * Endpoint namespace.
                   *

                Function get_pages has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function get_pages() {
                        // WC pages to check against.
                        $check_pages = array(
                            _x( 'Shop base', 'Page setting', 'woocommerce' ) => array(
                                'option'    => 'woocommerce_shop_page_id',

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

                    public function get_settings() {
                        // Get a list of terms used for product/order taxonomies.
                        $term_response = array();
                        $terms         = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
                        foreach ( $terms as $term ) {

                  Function get_database_info has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function get_database_info() {
                          global $wpdb;
                  
                          $tables        = array();
                          $database_size = 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

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

                      public function get_inactive_plugins() {
                          require_once ABSPATH . 'wp-admin/includes/plugin.php';
                  
                          if ( ! function_exists( 'get_plugins' ) ) {
                              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

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

                      private function check_if_field_item_exists( $section, $items, $fields ) {
                          if ( ! in_array( $section, $fields, true ) ) {
                              return false;
                          }
                  
                  

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

                                  'security'           => array(
                                      'description' => __( 'Security.', 'woocommerce' ),
                                      'type'        => 'object',
                                      'context'     => array( 'view' ),
                                      'readonly'    => true,
                  includes/rest-api/Controllers/Version1/class-wc-rest-customer-downloads-v1-controller.php on lines 216..235
                  includes/rest-api/Controllers/Version2/class-wc-rest-customer-downloads-v2-controller.php on lines 140..159

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

                  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