woocommerce/woocommerce

View on GitHub
includes/admin/importers/class-wc-product-csv-importer-controller.php

Summary

Maintainability
D
3 days
Test Coverage

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

<?php
/**
 * Class WC_Product_CSV_Importer_Controller file.
 *
 * @package WooCommerce\Admin\Importers
Severity: Minor
Found in includes/admin/importers/class-wc-product-csv-importer-controller.php - About 7 hrs to fix

    Method auto_map_columns has 84 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function auto_map_columns( $raw_headers, $num_indexes = true ) {
            $weight_unit    = get_option( 'woocommerce_weight_unit' );
            $dimension_unit = get_option( 'woocommerce_dimension_unit' );
    
            /*
    Severity: Major
    Found in includes/admin/importers/class-wc-product-csv-importer-controller.php - About 3 hrs to fix

      Method get_mapping_options has 83 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function get_mapping_options( $item = '' ) {
              // Get index for special column names.
              $index = $item;
      
              if ( preg_match( '/\d+/', $item, $matches ) ) {
      Severity: Major
      Found in includes/admin/importers/class-wc-product-csv-importer-controller.php - About 3 hrs to fix

        WC_Product_CSV_Importer_Controller has 23 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class WC_Product_CSV_Importer_Controller {
        
            /**
             * The path to the current file.
             *
        Severity: Minor
        Found in includes/admin/importers/class-wc-product-csv-importer-controller.php - About 2 hrs to fix

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

              protected function auto_map_columns( $raw_headers, $num_indexes = true ) {
                  $weight_unit    = get_option( 'woocommerce_weight_unit' );
                  $dimension_unit = get_option( 'woocommerce_dimension_unit' );
          
                  /*

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

              public function handle_upload() {
                  // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce already verified in WC_Product_CSV_Importer_Controller::upload_form_handler()
                  $file_url = isset( $_POST['file_url'] ) ? wc_clean( wp_unslash( $_POST['file_url'] ) ) : '';
          
                  if ( empty( $file_url ) ) {

            Method import has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function import() {
                    // Displaying this page triggers Ajax action to run the import with a valid nonce,
                    // therefore this page needs to be nonce protected as well.
                    check_admin_referer( 'woocommerce-csv-importer' );
            
            

              Method __construct has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function __construct() {
                      $default_steps = array(
                          'upload'  => array(
                              'name'    => __( 'Upload CSV file', 'woocommerce' ),
                              'view'    => array( $this, 'upload_form' ),

                Function handle_upload has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function handle_upload() {
                        // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce already verified in WC_Product_CSV_Importer_Controller::upload_form_handler()
                        $file_url = isset( $_POST['file_url'] ) ? wc_clean( wp_unslash( $_POST['file_url'] ) ) : '';
                
                        if ( empty( $file_url ) ) {

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

                    protected function output_errors() {
                        if ( ! $this->errors ) {
                            return;
                        }
                
                
                Severity: Minor
                Found in includes/admin/importers/class-wc-product-csv-importer-controller.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 new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
                Severity: Major
                Found in includes/admin/importers/class-wc-product-csv-importer-controller.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return new WP_Error( 'woocommerce_product_csv_importer_upload_invalid_file', __( 'Please upload or provide the link to a valid CSV file.', 'woocommerce' ) );
                  Severity: Major
                  Found in includes/admin/importers/class-wc-product-csv-importer-controller.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return ABSPATH . $file_url;
                    Severity: Major
                    Found in includes/admin/importers/class-wc-product-csv-importer-controller.php - About 30 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status