woothemes/woocommerce

View on GitHub
includes/import/class-wc-product-csv-importer.php

Summary

Maintainability
F
1 wk
Test Coverage

File class-wc-product-csv-importer.php has 652 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WooCommerce Product CSV importer
 *
 * @package WooCommerce\Import
Severity: Major
Found in includes/import/class-wc-product-csv-importer.php - About 1 day to fix

    Function expand_data has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function expand_data( $data ) {
            $data = apply_filters( 'woocommerce_product_importer_pre_expand_data', $data );
    
            // Images field maps to image and gallery id fields.
            if ( isset( $data['images'] ) ) {
    Severity: Minor
    Found in includes/import/class-wc-product-csv-importer.php - About 1 day 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 expand_data has 118 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function expand_data( $data ) {
            $data = apply_filters( 'woocommerce_product_importer_pre_expand_data', $data );
    
            // Images field maps to image and gallery id fields.
            if ( isset( $data['images'] ) ) {
    Severity: Major
    Found in includes/import/class-wc-product-csv-importer.php - About 4 hrs to fix

      WC_Product_CSV_Importer has 31 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class WC_Product_CSV_Importer extends WC_Product_Importer {
      
          /**
           * Tracks current row being parsed.
           *
      Severity: Minor
      Found in includes/import/class-wc-product-csv-importer.php - About 3 hrs to fix

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

            public function import() {
                $this->start_time = time();
                $index            = 0;
                $update_existing  = $this->params['update_existing'];
                $data             = array(
        Severity: Minor
        Found in includes/import/class-wc-product-csv-importer.php - About 3 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

        Function parse_categories_field has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

            public function parse_categories_field( $value ) {
                if ( empty( $value ) ) {
                    return array();
                }
        
        
        Severity: Minor
        Found in includes/import/class-wc-product-csv-importer.php - About 3 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

        Function read_file has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function read_file() {
                if ( ! WC_Product_CSV_Importer_Controller::is_file_valid_csv( $this->file ) ) {
                    wp_die( esc_html__( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
                }
        
        
        Severity: Minor
        Found in includes/import/class-wc-product-csv-importer.php - About 3 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 import has 74 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function import() {
                $this->start_time = time();
                $index            = 0;
                $update_existing  = $this->params['update_existing'];
                $data             = array(
        Severity: Major
        Found in includes/import/class-wc-product-csv-importer.php - About 2 hrs to fix

          Function set_parsed_data has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function set_parsed_data() {
                  $parse_functions = $this->get_formatting_callback();
                  $mapped_keys     = $this->get_mapped_keys();
                  $use_mb          = function_exists( 'mb_convert_encoding' );
          
          
          Severity: Minor
          Found in includes/import/class-wc-product-csv-importer.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 get_formatting_callback has 57 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function get_formatting_callback() {
          
                  /**
                   * Columns not mentioned here will get parsed with 'wc_clean'.
                   * column_name => callback.
          Severity: Major
          Found in includes/import/class-wc-product-csv-importer.php - About 2 hrs to fix

            Method parse_relative_field has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function parse_relative_field( $value ) {
                    global $wpdb;
            
                    if ( empty( $value ) ) {
                        return '';
            Severity: Minor
            Found in includes/import/class-wc-product-csv-importer.php - About 1 hr to fix

              Function parse_relative_field has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function parse_relative_field( $value ) {
                      global $wpdb;
              
                      if ( empty( $value ) ) {
                          return '';
              Severity: Minor
              Found in includes/import/class-wc-product-csv-importer.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 get_formatting_callback has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function get_formatting_callback() {
              
                      /**
                       * Columns not mentioned here will get parsed with 'wc_clean'.
                       * column_name => callback.
              Severity: Minor
              Found in includes/import/class-wc-product-csv-importer.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 read_file has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function read_file() {
                      if ( ! WC_Product_CSV_Importer_Controller::is_file_valid_csv( $this->file ) ) {
                          wp_die( esc_html__( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
                      }
              
              
              Severity: Minor
              Found in includes/import/class-wc-product-csv-importer.php - About 1 hr to fix

                Method parse_categories_field has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function parse_categories_field( $value ) {
                        if ( empty( $value ) ) {
                            return array();
                        }
                
                
                Severity: Minor
                Found in includes/import/class-wc-product-csv-importer.php - About 1 hr to fix

                  Method set_parsed_data has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function set_parsed_data() {
                          $parse_functions = $this->get_formatting_callback();
                          $mapped_keys     = $this->get_mapped_keys();
                          $use_mb          = function_exists( 'mb_convert_encoding' );
                  
                  
                  Severity: Minor
                  Found in includes/import/class-wc-product-csv-importer.php - About 1 hr to fix

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

                        public function parse_id_field( $value ) {
                            global $wpdb;
                    
                            $id = absint( $value );
                    
                    
                    Severity: Minor
                    Found in includes/import/class-wc-product-csv-importer.php - About 1 hr to fix

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

                          public function parse_id_field( $value ) {
                              global $wpdb;
                      
                              $id = absint( $value );
                      
                      
                      Severity: Minor
                      Found in includes/import/class-wc-product-csv-importer.php - About 45 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 parse_tags_field has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function parse_tags_field( $value ) {
                              if ( empty( $value ) ) {
                                  return array();
                              }
                      
                      
                      Severity: Minor
                      Found in includes/import/class-wc-product-csv-importer.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

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

                          public function parse_tags_spaces_field( $value ) {
                              if ( empty( $value ) ) {
                                  return array();
                              }
                      
                      
                      Severity: Minor
                      Found in includes/import/class-wc-product-csv-importer.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 '';
                      Severity: Major
                      Found in includes/import/class-wc-product-csv-importer.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return '';
                        Severity: Major
                        Found in includes/import/class-wc-product-csv-importer.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return $id;
                          Severity: Major
                          Found in includes/import/class-wc-product-csv-importer.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return $id;
                            Severity: Major
                            Found in includes/import/class-wc-product-csv-importer.php - About 30 mins to fix

                              There are no issues that match your filters.

                              Category
                              Status