woothemes/woocommerce

View on GitHub
includes/legacy/api/v2/class-wc-api-products.php

Summary

Maintainability
F
1 mo
Test Coverage

File class-wc-api-products.php has 1435 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WooCommerce API Products Class
 *
 * Handles requests to the /products endpoint
Severity: Major
Found in includes/legacy/api/v2/class-wc-api-products.php - About 3 days to fix

    Function save_product_meta has a Cognitive Complexity of 146 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function save_product_meta( $product, $data ) {
            global $wpdb;
    
            // Virtual
            if ( isset( $data['virtual'] ) ) {
    Severity: Minor
    Found in includes/legacy/api/v2/class-wc-api-products.php - About 2 days 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 save_variations has a Cognitive Complexity of 83 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function save_variations( $product, $request ) {
            global $wpdb;
    
            $id         = $product->get_id();
            $attributes = $product->get_attributes();
    Severity: Minor
    Found in includes/legacy/api/v2/class-wc-api-products.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 save_product_meta has 258 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function save_product_meta( $product, $data ) {
            global $wpdb;
    
            // Virtual
            if ( isset( $data['virtual'] ) ) {
    Severity: Major
    Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 day to fix

      Function save_default_attributes has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function save_default_attributes( $product, $request ) {
              // Update default attributes options setting.
              if ( isset( $request['default_attribute'] ) ) {
                  $request['default_attributes'] = $request['default_attribute'];
              }
      Severity: Minor
      Found in includes/legacy/api/v2/class-wc-api-products.php - About 5 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 save_variations has 117 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function save_variations( $product, $request ) {
              global $wpdb;
      
              $id         = $product->get_id();
              $attributes = $product->get_attributes();
      Severity: Major
      Found in includes/legacy/api/v2/class-wc-api-products.php - About 4 hrs to fix

        WC_API_Products has 36 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class WC_API_Products extends WC_API_Resource {
        
            /** @var string $base the route base */
            protected $base = '/products';
        
        
        Severity: Minor
        Found in includes/legacy/api/v2/class-wc-api-products.php - About 4 hrs to fix

          Function save_product_images has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function save_product_images( $product, $images ) {
                  if ( is_array( $images ) ) {
                      $gallery = array();
          
                      foreach ( $images as $image ) {
          Severity: Minor
          Found in includes/legacy/api/v2/class-wc-api-products.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 delete_product has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
          Open

              public function delete_product( $id, $force = false ) {
          
                  $id = $this->validate_request( $id, 'product', 'delete' );
          
                  if ( is_wp_error( $id ) ) {
          Severity: Minor
          Found in includes/legacy/api/v2/class-wc-api-products.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 get_product_data has 72 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function get_product_data( $product ) {
                  if ( is_numeric( $product ) ) {
                      $product = wc_get_product( $product );
                  }
          
          
          Severity: Major
          Found in includes/legacy/api/v2/class-wc-api-products.php - About 2 hrs to fix

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

                public function bulk( $data ) {
            
                    try {
                        if ( ! isset( $data['products'] ) ) {
                            throw new WC_API_Exception( 'woocommerce_api_missing_products_data', sprintf( __( 'No %1$s data specified to create/edit %1$s', 'woocommerce' ), 'products' ), 400 );
            Severity: Minor
            Found in includes/legacy/api/v2/class-wc-api-products.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 create_product has 63 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function create_product( $data ) {
                    $id = 0;
            
                    try {
                        if ( ! isset( $data['product'] ) ) {
            Severity: Major
            Found in includes/legacy/api/v2/class-wc-api-products.php - About 2 hrs to fix

              Method edit_product_attribute has 53 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function edit_product_attribute( $id, $data ) {
                      global $wpdb;
              
                      try {
                          if ( ! isset( $data['product_attribute'] ) ) {
              Severity: Major
              Found in includes/legacy/api/v2/class-wc-api-products.php - About 2 hrs to fix

                Function edit_product has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function edit_product( $id, $data ) {
                        try {
                            if ( ! isset( $data['product'] ) ) {
                                throw new WC_API_Exception( 'woocommerce_api_missing_product_data', sprintf( __( 'No %1$s data specified to edit %1$s', 'woocommerce' ), 'product' ), 400 );
                            }
                Severity: Minor
                Found in includes/legacy/api/v2/class-wc-api-products.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 edit_product has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function edit_product( $id, $data ) {
                        try {
                            if ( ! isset( $data['product'] ) ) {
                                throw new WC_API_Exception( 'woocommerce_api_missing_product_data', sprintf( __( 'No %1$s data specified to edit %1$s', 'woocommerce' ), 'product' ), 400 );
                            }
                Severity: Major
                Found in includes/legacy/api/v2/class-wc-api-products.php - About 2 hrs to fix

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

                      public function register_routes( $routes ) {
                  
                          # GET/POST /products
                          $routes[ $this->base ] = array(
                              array( array( $this, 'get_products' ), WC_API_Server::READABLE ),
                  Severity: Minor
                  Found in includes/legacy/api/v2/class-wc-api-products.php - About 2 hrs to fix

                    Method bulk has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function bulk( $data ) {
                    
                            try {
                                if ( ! isset( $data['products'] ) ) {
                                    throw new WC_API_Exception( 'woocommerce_api_missing_products_data', sprintf( __( 'No %1$s data specified to create/edit %1$s', 'woocommerce' ), 'products' ), 400 );
                    Severity: Minor
                    Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

                      Method create_product_attribute has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function create_product_attribute( $data ) {
                              global $wpdb;
                      
                              try {
                                  if ( ! isset( $data['product_attribute'] ) ) {
                      Severity: Minor
                      Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

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

                            public function create_product( $data ) {
                                $id = 0;
                        
                                try {
                                    if ( ! isset( $data['product'] ) ) {
                        Severity: Minor
                        Found in includes/legacy/api/v2/class-wc-api-products.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 get_variation_data has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            private function get_variation_data( $product ) {
                                $prices_precision = wc_get_price_decimals();
                                $variations       = array();
                        
                                foreach ( $product->get_children() as $child_id ) {
                        Severity: Minor
                        Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

                          Method delete_product has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function delete_product( $id, $force = false ) {
                          
                                  $id = $this->validate_request( $id, 'product', 'delete' );
                          
                                  if ( is_wp_error( $id ) ) {
                          Severity: Minor
                          Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

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

                                private function get_images( $product ) {
                                    $images        = $attachment_ids = array();
                                    $product_image = $product->get_image_id();
                            
                                    // Add featured image.
                            Severity: Minor
                            Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

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

                                  public function delete_product_attribute( $id ) {
                                      global $wpdb;
                              
                                      try {
                                          // Check permissions
                              Severity: Minor
                              Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

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

                                    private function save_product_shipping_data( $product, $data ) {
                                        if ( isset( $data['weight'] ) ) {
                                            $product->set_weight( '' === $data['weight'] ? '' : wc_format_decimal( $data['weight'] ) );
                                        }
                                
                                
                                Severity: Minor
                                Found in includes/legacy/api/v2/class-wc-api-products.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 save_product_images has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    protected function save_product_images( $product, $images ) {
                                        if ( is_array( $images ) ) {
                                            $gallery = array();
                                
                                            foreach ( $images as $image ) {
                                Severity: Minor
                                Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

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

                                      protected function save_default_attributes( $product, $request ) {
                                          // Update default attributes options setting.
                                          if ( isset( $request['default_attribute'] ) ) {
                                              $request['default_attributes'] = $request['default_attribute'];
                                          }
                                  Severity: Minor
                                  Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

                                    Method query_products has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        private function query_products( $args ) {
                                    
                                            // Set base query arguments
                                            $query_args = array(
                                                'fields'      => 'ids',
                                    Severity: Minor
                                    Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

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

                                          public function get_product_category( $id, $fields = null ) {
                                              try {
                                                  $id = absint( $id );
                                      
                                                  // Validate ID
                                      Severity: Minor
                                      Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

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

                                            public function get_product_attribute( $id, $fields = null ) {
                                                global $wpdb;
                                        
                                                try {
                                                    $id = absint( $id );
                                        Severity: Minor
                                        Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

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

                                              private function save_product_shipping_data( $product, $data ) {
                                                  if ( isset( $data['weight'] ) ) {
                                                      $product->set_weight( '' === $data['weight'] ? '' : wc_format_decimal( $data['weight'] ) );
                                                  }
                                          
                                          
                                          Severity: Minor
                                          Found in includes/legacy/api/v2/class-wc-api-products.php - About 1 hr to fix

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

                                                private function get_images( $product ) {
                                                    $images        = $attachment_ids = array();
                                                    $product_image = $product->get_image_id();
                                            
                                                    // Add featured image.
                                            Severity: Minor
                                            Found in includes/legacy/api/v2/class-wc-api-products.php - About 55 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 create_product_attribute has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                public function create_product_attribute( $data ) {
                                                    global $wpdb;
                                            
                                                    try {
                                                        if ( ! isset( $data['product_attribute'] ) ) {
                                            Severity: Minor
                                            Found in includes/legacy/api/v2/class-wc-api-products.php - About 55 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 edit_product_attribute has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                public function edit_product_attribute( $id, $data ) {
                                                    global $wpdb;
                                            
                                                    try {
                                                        if ( ! isset( $data['product_attribute'] ) ) {
                                            Severity: Minor
                                            Found in includes/legacy/api/v2/class-wc-api-products.php - About 55 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 validate_attribute_data has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                            Open

                                                protected function validate_attribute_data( $name, $slug, $type, $order_by, $new_data = true ) {
                                            Severity: Minor
                                            Found in includes/legacy/api/v2/class-wc-api-products.php - About 35 mins to fix

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

                                                  public function get_product_orders( $id, $fields = null, $filter = array(), $status = null, $page = 1 ) {
                                              Severity: Minor
                                              Found in includes/legacy/api/v2/class-wc-api-products.php - About 35 mins to fix

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

                                                    protected function validate_attribute_data( $name, $slug, $type, $order_by, $new_data = true ) {
                                                        if ( empty( $name ) ) {
                                                            throw new WC_API_Exception( 'woocommerce_api_missing_product_attribute_name', sprintf( __( 'Missing parameter %s', 'woocommerce' ), 'name' ), 400 );
                                                        }
                                                
                                                
                                                Severity: Minor
                                                Found in includes/legacy/api/v2/class-wc-api-products.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 delete_product_attribute has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                Open

                                                    public function delete_product_attribute( $id ) {
                                                        global $wpdb;
                                                
                                                        try {
                                                            // Check permissions
                                                Severity: Minor
                                                Found in includes/legacy/api/v2/class-wc-api-products.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 save_downloadable_files has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                Open

                                                    private function save_downloadable_files( $product, $downloads, $deprecated = 0 ) {
                                                        if ( $deprecated ) {
                                                            wc_deprecated_argument( 'variation_id', '3.0', 'save_downloadable_files() does not require a variation_id anymore.' );
                                                        }
                                                
                                                
                                                Severity: Minor
                                                Found in includes/legacy/api/v2/class-wc-api-products.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 set_product_image_as_attachment has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                Open

                                                    protected function set_product_image_as_attachment( $upload, $id ) {
                                                        $info    = wp_check_filetype( $upload['file'] );
                                                        $title   = '';
                                                        $content = '';
                                                
                                                
                                                Severity: Minor
                                                Found in includes/legacy/api/v2/class-wc-api-products.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_attributes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                Open

                                                    private function get_attributes( $product ) {
                                                
                                                        $attributes = array();
                                                
                                                        if ( $product->is_type( 'variation' ) ) {
                                                Severity: Minor
                                                Found in includes/legacy/api/v2/class-wc-api-products.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

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

                                                    public function get_product_category( $id, $fields = null ) {
                                                        try {
                                                            $id = absint( $id );
                                                
                                                            // Validate ID
                                                Severity: Minor
                                                Found in includes/legacy/api/v2/class-wc-api-products.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

                                                        if ( isset( $data['attributes'] ) ) {
                                                            $attributes = array();
                                                
                                                            foreach ( $data['attributes'] as $attribute ) {
                                                                $is_taxonomy = 0;
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 3 days to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 1445..1525

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

                                                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

                                                    public function bulk( $data ) {
                                                
                                                        try {
                                                            if ( ! isset( $data['products'] ) ) {
                                                                throw new WC_API_Exception( 'woocommerce_api_missing_products_data', sprintf( __( 'No %1$s data specified to create/edit %1$s', 'woocommerce' ), 'products' ), 400 );
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 2 days to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 3037..3103

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

                                                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

                                                    protected function validate_attribute_data( $name, $slug, $type, $order_by, $new_data = true ) {
                                                        if ( empty( $name ) ) {
                                                            throw new WC_API_Exception( 'woocommerce_api_missing_product_attribute_name', sprintf( __( 'Missing parameter %s', 'woocommerce' ), 'name' ), 400 );
                                                        }
                                                
                                                
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 2 days to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 2480..2504

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

                                                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

                                                    public function get_product_category( $id, $fields = null ) {
                                                        try {
                                                            $id = absint( $id );
                                                
                                                            // Validate ID
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 2 days to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 646..692

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

                                                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

                                                    public function delete_product( $id, $force = false ) {
                                                
                                                        $id = $this->validate_request( $id, 'product', 'delete' );
                                                
                                                        if ( is_wp_error( $id ) ) {
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 474..529

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

                                                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 ( in_array( $product->get_type(), array( 'variable', 'grouped' ) ) ) {
                                                
                                                            // Variable and grouped products have no prices.
                                                            $product->set_regular_price( '' );
                                                            $product->set_sale_price( '' );
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 1528..1575

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

                                                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 save_product_shipping_data( $product, $data ) {
                                                        if ( isset( $data['weight'] ) ) {
                                                            $product->set_weight( '' === $data['weight'] ? '' : wc_format_decimal( $data['weight'] ) );
                                                        }
                                                
                                                
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 1964..2007

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

                                                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_images( $product ) {
                                                        $images        = $attachment_ids = array();
                                                        $product_image = $product->get_image_id();
                                                
                                                        // Add featured image.
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 2073..2126

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

                                                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

                                                    public function get_product_attribute( $id, $fields = null ) {
                                                        global $wpdb;
                                                
                                                        try {
                                                            $id = absint( $id );
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 2427..2466

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

                                                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

                                                    protected function save_default_attributes( $product, $request ) {
                                                        // Update default attributes options setting.
                                                        if ( isset( $request['default_attribute'] ) ) {
                                                            $request['default_attributes'] = $request['default_attribute'];
                                                        }
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 1329..1376

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

                                                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 ( isset( $data['attributes'] ) ) {
                                                                $_attributes = array();
                                                
                                                                foreach ( $data['attributes'] as $attribute_key => $attribute ) {
                                                                    if ( ! isset( $attribute['name'] ) ) {
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 1908..1946

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

                                                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

                                                    protected function set_product_image_as_attachment( $upload, $id ) {
                                                        $info    = wp_check_filetype( $upload['file'] );
                                                        $title   = '';
                                                        $content = '';
                                                
                                                
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 2268..2296

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

                                                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

                                                    public function get_product_orders( $id, $fields = null, $filter = array(), $status = null, $page = 1 ) {
                                                        global $wpdb;
                                                
                                                        $id = $this->validate_request( $id, 'product', 'read' );
                                                
                                                
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 7 hrs to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 577..604

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

                                                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 save_downloadable_files( $product, $downloads, $deprecated = 0 ) {
                                                        if ( $deprecated ) {
                                                            wc_deprecated_argument( 'variation_id', '3.0', 'save_downloadable_files() does not require a variation_id anymore.' );
                                                        }
                                                
                                                
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 6 hrs to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 2018..2042

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

                                                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

                                                    public function get_product_attributes( $fields = null ) {
                                                        try {
                                                            // Permissions check
                                                            if ( ! current_user_can( 'manage_product_terms' ) ) {
                                                                throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_product_attributes', __( 'You do not have permission to read product attributes', 'woocommerce' ), 401 );
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 6 hrs to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 2390..2415

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

                                                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

                                                    public function get_product_reviews( $id, $fields = null ) {
                                                
                                                        $id = $this->validate_request( $id, 'product', 'read' );
                                                
                                                        if ( is_wp_error( $id ) ) {
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 6 hrs to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 539..564

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

                                                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

                                                    public function get_product_categories( $fields = null ) {
                                                        try {
                                                            // Permissions check
                                                            if ( ! current_user_can( 'manage_product_terms' ) ) {
                                                                throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_product_categories', __( 'You do not have permission to read product categories', 'woocommerce' ), 401 );
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 3 other locations - About 5 hrs to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 615..634
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 881..900
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 3113..3132

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

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

                                                    public function get_products( $fields = null, $type = null, $filter = array(), $page = 1 ) {
                                                
                                                        if ( ! empty( $type ) ) {
                                                            $filter['type'] = $type;
                                                        }
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 2 other locations - About 3 hrs to fix
                                                includes/legacy/api/v1/class-wc-api-products.php on lines 70..94
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 148..172

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

                                                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 ( isset( $data['sku'] ) ) {
                                                            $sku     = $product->get_sku();
                                                            $new_sku = wc_clean( $data['sku'] );
                                                
                                                            if ( '' == $new_sku ) {
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 3 hrs to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 1424..1442

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

                                                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

                                                    public function get_products_count( $type = null, $filter = array() ) {
                                                        try {
                                                            if ( ! current_user_can( 'read_private_products' ) ) {
                                                                throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_products_count', __( 'You do not have permission to read the products count', 'woocommerce' ), 401 );
                                                            }
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 3 hrs to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 231..247

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

                                                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 ( isset( $image['position'] ) && 0 == $image['position'] ) {
                                                                    $attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
                                                
                                                                    if ( 0 === $attachment_id && isset( $image['src'] ) ) {
                                                                        $upload = $this->upload_product_image( esc_url_raw( $image['src'] ) );
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 2 hrs to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 2142..2170

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

                                                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

                                                            $insert = $wpdb->insert(
                                                                $wpdb->prefix . 'woocommerce_attribute_taxonomies',
                                                                array(
                                                                    'attribute_label'   => $data['name'],
                                                                    'attribute_name'    => $data['slug'],
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 hr to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 2556..2566

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

                                                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 ( isset( $data['type'] ) && ! in_array( wc_clean( $data['type'] ), array_keys( wc_get_product_types() ) ) ) {
                                                                throw new WC_API_Exception( 'woocommerce_api_invalid_product_type', sprintf( __( 'Invalid product type - the product type must be any of these: %s', 'woocommerce' ), implode( ', ', array_keys( wc_get_product_types() ) ) ), 400 );
                                                            }
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 hr to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 422..424

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

                                                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 ( 'yes' == $is_downloadable ) {
                                                
                                                            // Downloadable files
                                                            if ( isset( $data['downloads'] ) && is_array( $data['downloads'] ) ) {
                                                                $product = $this->save_downloadable_files( $product, $data['downloads'] );
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 1 hr to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 1713..1729

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

                                                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_downloadable ) {
                                                                // Downloadable files.
                                                                if ( isset( $data['downloads'] ) && is_array( $data['downloads'] ) ) {
                                                                    $variation = $this->save_downloadable_files( $variation, $data['downloads'] );
                                                                }
                                                Severity: Minor
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 55 mins to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 1827..1842

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

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

                                                    protected function get_attribute_options( $product_id, $attribute ) {
                                                        if ( isset( $attribute['is_taxonomy'] ) && $attribute['is_taxonomy'] ) {
                                                            return wc_get_product_terms( $product_id, $attribute['name'], array( 'fields' => 'names' ) );
                                                        } elseif ( isset( $attribute['value'] ) ) {
                                                            return array_map( 'trim', explode( '|', $attribute['value'] ) );
                                                Severity: Major
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 4 other locations - About 55 mins to fix
                                                includes/legacy/api/v1/class-wc-api-products.php on lines 475..483
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 2305..2313
                                                includes/rest-api/Controllers/Version1/class-wc-rest-products-v1-controller.php on lines 372..380
                                                includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php on lines 526..540

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

                                                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

                                                        try {
                                                            if ( ! isset( $data['product'] ) ) {
                                                                throw new WC_API_Exception( 'woocommerce_api_missing_product_data', sprintf( __( 'No %1$s data specified to create %1$s', 'woocommerce' ), 'product' ), 400 );
                                                            }
                                                
                                                
                                                Severity: Minor
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 45 mins to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 261..361

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

                                                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( $args['sku'] ) ) {
                                                            if ( ! is_array( $query_args['meta_query'] ) ) {
                                                                $query_args['meta_query'] = array();
                                                            }
                                                
                                                
                                                Severity: Minor
                                                Found in includes/legacy/api/v2/class-wc-api-products.php and 1 other location - About 40 mins to fix
                                                includes/legacy/api/v3/class-wc-api-products.php on lines 1118..1130

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

                                                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