woothemes/woocommerce

View on GitHub
includes/data-stores/class-wc-product-data-store-cpt.php

Summary

Maintainability
F
2 wks
Test Coverage

File class-wc-product-data-store-cpt.php has 1385 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WC_Product_Data_Store_CPT class file.
 *
 * @package WooCommerce\Classes
Severity: Major
Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 3 days to fix

    Method get_wp_query_args has 202 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function get_wp_query_args( $query_vars ) {
    
            // Map query vars to ones that get_wp_query_args or WP_Query recognize.
            $key_mapping = array(
                'status'         => 'post_status',
    Severity: Major
    Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 day to fix

      Function get_wp_query_args has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function get_wp_query_args( $query_vars ) {
      
              // Map query vars to ones that get_wp_query_args or WP_Query recognize.
              $key_mapping = array(
                  'status'         => 'post_status',
      Severity: Minor
      Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 6 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

      WC_Product_Data_Store_CPT has 45 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface, WC_Product_Data_Store_Interface {
      
          /**
           * Data stored in meta keys, but not considered "meta".
           *
      Severity: Minor
      Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 6 hrs to fix

        Function search_products has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
        Open

            public function search_products( $term, $type = '', $include_variations = false, $all_statuses = false, $limit = null, $include = null, $exclude = null ) {
                global $wpdb;
        
                $custom_results = apply_filters( 'woocommerce_product_pre_search_products', false, $term, $type, $include_variations, $all_statuses, $limit );
        
        
        Severity: Minor
        Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 4 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 update_post_meta has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function update_post_meta( &$product, $force = false ) {
                $meta_key_to_props = array(
                    '_sku'                   => 'sku',
                    '_regular_price'         => 'regular_price',
                    '_sale_price'            => 'sale_price',
        Severity: Minor
        Found in includes/data-stores/class-wc-product-data-store-cpt.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 search_products has 95 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function search_products( $term, $type = '', $include_variations = false, $all_statuses = false, $limit = null, $include = null, $exclude = null ) {
                global $wpdb;
        
                $custom_results = apply_filters( 'woocommerce_product_pre_search_products', false, $term, $type, $include_variations, $all_statuses, $limit );
        
        
        Severity: Major
        Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 3 hrs to fix

          Method update_post_meta has 88 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function update_post_meta( &$product, $force = false ) {
                  $meta_key_to_props = array(
                      '_sku'                   => 'sku',
                      '_regular_price'         => 'regular_price',
                      '_sale_price'            => 'sale_price',
          Severity: Major
          Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 3 hrs to fix

            Function find_matching_product_variation has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
            Open

                public function find_matching_product_variation( $product, $match_attributes = array() ) {
                    global $wpdb;
            
                    $meta_attribute_names = array();
            
            
            Severity: Minor
            Found in includes/data-stores/class-wc-product-data-store-cpt.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 handle_updated_props has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function handle_updated_props( &$product ) {
                    $price_is_synced = $product->is_type( array( 'variable', 'grouped' ) );
            
                    if ( ! $price_is_synced ) {
                        if ( in_array( 'regular_price', $this->updated_props, true ) || in_array( 'sale_price', $this->updated_props, true ) ) {
            Severity: Minor
            Found in includes/data-stores/class-wc-product-data-store-cpt.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 update_attributes has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function update_attributes( &$product, $force = false ) {
                    $changes = $product->get_changes();
            
                    if ( $force || array_key_exists( 'attributes', $changes ) ) {
                        $attributes  = $product->get_attributes();
            Severity: Minor
            Found in includes/data-stores/class-wc-product-data-store-cpt.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 update has 60 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function update( &$product ) {
                    $product->save_meta_data();
                    $changes = $product->get_changes();
            
                    // Only update the post when the post data changes.
            Severity: Major
            Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 2 hrs to fix

              Method find_matching_product_variation has 52 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function find_matching_product_variation( $product, $match_attributes = array() ) {
                      global $wpdb;
              
                      $meta_attribute_names = array();
              
              
              Severity: Major
              Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 2 hrs to fix

                Method read_product_data has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function read_product_data( &$product ) {
                        $id                = $product->get_id();
                        $post_meta_values  = get_post_meta( $id );
                        $meta_key_to_props = array(
                            '_sku'                   => 'sku',
                Severity: Minor
                Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

                  Function update_visibility has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                      protected function update_visibility( &$product, $force = false ) {
                          $changes = $product->get_changes();
                  
                          if ( $force || array_intersect( array( 'featured', 'stock_status', 'average_rating', 'catalog_visibility' ), array_keys( $changes ) ) ) {
                              $terms = array();
                  Severity: Minor
                  Found in includes/data-stores/class-wc-product-data-store-cpt.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 update_product_stock has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function update_product_stock( $product_id_with_stock, $stock_quantity = null, $operation = 'set' ) {
                          global $wpdb;
                  
                          // Ensures a row exists to update.
                          add_post_meta( $product_id_with_stock, '_stock', 0, true );
                  Severity: Minor
                  Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

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

                        protected function read_attributes( &$product ) {
                            $meta_attributes = get_post_meta( $product->get_id(), '_product_attributes', true );
                    
                            if ( ! empty( $meta_attributes ) && is_array( $meta_attributes ) ) {
                                $attributes = array();
                    Severity: Minor
                    Found in includes/data-stores/class-wc-product-data-store-cpt.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 create has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function create( &$product ) {
                            if ( ! $product->get_date_created( 'edit' ) ) {
                                $product->set_date_created( time() );
                            }
                    
                    
                    Severity: Minor
                    Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

                      Method handle_updated_props has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          protected function handle_updated_props( &$product ) {
                              $price_is_synced = $product->is_type( array( 'variable', 'grouped' ) );
                      
                              if ( ! $price_is_synced ) {
                                  if ( in_array( 'regular_price', $this->updated_props, true ) || in_array( 'sale_price', $this->updated_props, true ) ) {
                      Severity: Minor
                      Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

                        Method read_attributes has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            protected function read_attributes( &$product ) {
                                $meta_attributes = get_post_meta( $product->get_id(), '_product_attributes', true );
                        
                                if ( ! empty( $meta_attributes ) && is_array( $meta_attributes ) ) {
                                    $attributes = array();
                        Severity: Minor
                        Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

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

                              public function get_related_products_query( $cats_array, $tags_array, $exclude_ids, $limit ) {
                                  global $wpdb;
                          
                                  $include_term_ids            = array_merge( $cats_array, $tags_array );
                                  $exclude_term_ids            = array();
                          Severity: Minor
                          Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

                            Method update_product_sales has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public function update_product_sales( $product_id, $quantity = null, $operation = 'set' ) {
                                    global $wpdb;
                                    add_post_meta( $product_id, 'total_sales', 0, true );
                            
                                    // Update stock in DB directly.
                            Severity: Minor
                            Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

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

                                  public function get_on_sale_products() {
                                      global $wpdb;
                              
                                      $exclude_term_ids            = array();
                                      $outofstock_join             = '';
                              Severity: Minor
                              Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

                                Function update has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function update( &$product ) {
                                        $product->save_meta_data();
                                        $changes = $product->get_changes();
                                
                                        // Only update the post when the post data changes.
                                Severity: Minor
                                Found in includes/data-stores/class-wc-product-data-store-cpt.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 create_all_product_variations has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function create_all_product_variations( $product, $limit = -1 ) {
                                        $count = 0;
                                
                                        if ( ! $product ) {
                                            return $count;
                                Severity: Minor
                                Found in includes/data-stores/class-wc-product-data-store-cpt.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 update_attributes has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    protected function update_attributes( &$product, $force = false ) {
                                        $changes = $product->get_changes();
                                
                                        if ( $force || array_key_exists( 'attributes', $changes ) ) {
                                            $attributes  = $product->get_attributes();
                                Severity: Minor
                                Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

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

                                      public function create_all_product_variations( $product, $limit = -1 ) {
                                          $count = 0;
                                  
                                          if ( ! $product ) {
                                              return $count;
                                  Severity: Minor
                                  Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

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

                                        protected function update_visibility( &$product, $force = false ) {
                                            $changes = $product->get_changes();
                                    
                                            if ( $force || array_intersect( array( 'featured', 'stock_status', 'average_rating', 'catalog_visibility' ), array_keys( $changes ) ) ) {
                                                $terms = array();
                                    Severity: Minor
                                    Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

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

                                          protected function update_downloads( &$product, $force = false ) {
                                              $changes = $product->get_changes();
                                      
                                              if ( $force || array_key_exists( 'downloads', $changes ) ) {
                                                  $downloads   = $product->get_downloads();
                                      Severity: Minor
                                      Found in includes/data-stores/class-wc-product-data-store-cpt.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 has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                          public function read( &$product ) {
                                              $product->set_defaults();
                                              $post_object = get_post( $product->get_id() );
                                      
                                              if ( ! $product->get_id() || ! $post_object || 'product' !== $post_object->post_type ) {
                                      Severity: Minor
                                      Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 1 hr to fix

                                        Method search_products has 7 arguments (exceeds 4 allowed). Consider refactoring.
                                        Open

                                            public function search_products( $term, $type = '', $include_variations = false, $all_statuses = false, $limit = null, $include = null, $exclude = null ) {
                                        Severity: Major
                                        Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 50 mins to fix

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

                                              protected function update_terms( &$product, $force = false ) {
                                                  $changes = $product->get_changes();
                                          
                                                  if ( $force || array_key_exists( 'category_ids', $changes ) ) {
                                                      $categories = $product->get_category_ids( 'edit' );
                                          Severity: Minor
                                          Found in includes/data-stores/class-wc-product-data-store-cpt.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

                                          Method get_related_products has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                          Open

                                              public function get_related_products( $cats_array, $tags_array, $exclude_ids, $limit, $product_id ) {
                                          Severity: Minor
                                          Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 35 mins to fix

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

                                                protected function read_downloads( &$product ) {
                                                    $meta_values = array_filter( (array) get_post_meta( $product->get_id(), '_downloadable_files', true ) );
                                            
                                                    if ( $meta_values ) {
                                                        $downloads = array();
                                            Severity: Minor
                                            Found in includes/data-stores/class-wc-product-data-store-cpt.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 get_related_products_query has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                public function get_related_products_query( $cats_array, $tags_array, $exclude_ids, $limit ) {
                                                    global $wpdb;
                                            
                                                    $include_term_ids            = array_merge( $cats_array, $tags_array );
                                                    $exclude_term_ids            = array();
                                            Severity: Minor
                                            Found in includes/data-stores/class-wc-product-data-store-cpt.php - About 25 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

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

                                                    $meta_key_to_props = array(
                                                        '_sku'                   => 'sku',
                                                        '_regular_price'         => 'regular_price',
                                                        '_sale_price'            => 'sale_price',
                                                        '_price'                 => 'price',
                                            Severity: Major
                                            Found in includes/data-stores/class-wc-product-data-store-cpt.php and 1 other location - About 4 hrs to fix
                                            includes/wc-update-functions.php on lines 1408..1441

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

                                            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

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

                                                    $meta_key_to_props = array(
                                                        '_sku'                   => 'sku',
                                                        '_regular_price'         => 'regular_price',
                                                        '_sale_price'            => 'sale_price',
                                                        '_sale_price_dates_from' => 'date_on_sale_from',
                                            Severity: Major
                                            Found in includes/data-stores/class-wc-product-data-store-cpt.php and 1 other location - About 3 hrs to fix
                                            includes/rest-api/Server.php on lines 98..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 158.

                                            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 ( ! empty( $meta_value['is_taxonomy'] ) ) {
                                                                if ( ! taxonomy_exists( $meta_value['name'] ) ) {
                                                                    continue;
                                                                }
                                                                $id      = wc_attribute_taxonomy_id_by_name( $meta_value['name'] );
                                            Severity: Major
                                            Found in includes/data-stores/class-wc-product-data-store-cpt.php and 1 other location - About 1 hr to fix
                                            includes/data-stores/class-wc-product-variable-data-store-cpt.php on lines 68..77

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

                                            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

                                            Similar blocks of code found in 4 locations. Consider refactoring.
                                            Open

                                                        if ( doing_action( 'save_post' ) ) {
                                                            $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $product->get_id() ) );
                                                            clean_post_cache( $product->get_id() );
                                                        } else {
                                                            wp_update_post( array_merge( array( 'ID' => $product->get_id() ), $post_data ) );
                                            Severity: Major
                                            Found in includes/data-stores/class-wc-product-data-store-cpt.php and 3 other locations - About 30 mins to fix
                                            includes/data-stores/abstract-wc-order-data-store-cpt.php on lines 165..170
                                            includes/data-stores/class-wc-coupon-data-store-cpt.php on lines 181..186
                                            includes/data-stores/class-wc-product-variation-data-store-cpt.php on lines 240..245

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

                                            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