woothemes/woocommerce

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

Summary

Maintainability
F
2 mos
Test Coverage

File class-wc-api-products.php has 2018 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/v3/class-wc-api-products.php - About 5 days to fix

    Function save_product_meta has a Cognitive Complexity of 147 (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/v3/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 86 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function save_variations( $product, $request ) {
            global $wpdb;
    
            $id         = $product->get_id();
            $variations = $request['variations'];
    Severity: Minor
    Found in includes/legacy/api/v3/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 262 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/v3/class-wc-api-products.php - About 1 day to fix

      WC_API_Products has 59 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: Major
      Found in includes/legacy/api/v3/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/v3/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

        Function save_product_images has a Cognitive Complexity of 35 (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/v3/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 125 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function save_variations( $product, $request ) {
                global $wpdb;
        
                $id         = $product->get_id();
                $variations = $request['variations'];
        Severity: Major
        Found in includes/legacy/api/v3/class-wc-api-products.php - About 5 hrs to fix

          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/v3/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 register_routes has 82 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: Major
          Found in includes/legacy/api/v3/class-wc-api-products.php - About 3 hrs to fix

            Method get_product_data has 73 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/v3/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/v3/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 67 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/v3/class-wc-api-products.php - About 2 hrs to fix

                Function edit_product has a Cognitive Complexity of 17 (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/v3/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 54 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/v3/class-wc-api-products.php - About 2 hrs to fix

                  Method edit_product_attribute has 54 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/v3/class-wc-api-products.php - About 2 hrs to fix

                    Function create_product has a Cognitive Complexity of 16 (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/v3/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_attribute has 49 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/v3/class-wc-api-products.php - About 1 hr 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/v3/class-wc-api-products.php - About 1 hr to fix

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

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

                          Method get_variation_data has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

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

                            Method query_products has 43 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/v3/class-wc-api-products.php - About 1 hr to fix

                              Method edit_product_category has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  public function edit_product_category( $id, $data ) {
                                      global $wpdb;
                              
                                      try {
                                          if ( ! isset( $data['product_category'] ) ) {
                              Severity: Minor
                              Found in includes/legacy/api/v3/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/v3/class-wc-api-products.php - About 1 hr to fix

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

                                      public function edit_product_category( $id, $data ) {
                                          global $wpdb;
                                  
                                          try {
                                              if ( ! isset( $data['product_category'] ) ) {
                                  Severity: Minor
                                  Found in includes/legacy/api/v3/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 39 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/v3/class-wc-api-products.php - About 1 hr to fix

                                    Method delete_product_attribute has 38 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/v3/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/v3/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/v3/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_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/v3/class-wc-api-products.php - About 1 hr to fix

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

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

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

                                                public function create_product_attribute_term( $attribute_id, $data ) {
                                                    global $wpdb;
                                            
                                                    try {
                                                        if ( ! isset( $data['product_attribute_term'] ) ) {
                                            Severity: Minor
                                            Found in includes/legacy/api/v3/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/v3/class-wc-api-products.php - About 1 hr to fix

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

                                                    public function create_product_category( $data ) {
                                                        global $wpdb;
                                                
                                                        try {
                                                            if ( ! isset( $data['product_category'] ) ) {
                                                Severity: Minor
                                                Found in includes/legacy/api/v3/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 edit_product_attribute_term has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                                Open

                                                    public function edit_product_attribute_term( $attribute_id, $id, $data ) {
                                                        global $wpdb;
                                                
                                                        try {
                                                            if ( ! isset( $data['product_attribute_term'] ) ) {
                                                Severity: Minor
                                                Found in includes/legacy/api/v3/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/v3/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/v3/class-wc-api-products.php - About 1 hr to fix

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

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

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

                                                            public function get_product( $id, $fields = null ) {
                                                        
                                                                $id = $this->validate_request( $id, 'product', 'read' );
                                                        
                                                                if ( is_wp_error( $id ) ) {
                                                        Severity: Minor
                                                        Found in includes/legacy/api/v3/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 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/v3/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/v3/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/v3/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 query_products has a Cognitive Complexity of 8 (exceeds 5 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/v3/class-wc-api-products.php - About 45 mins to fix

                                                        Cognitive Complexity

                                                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                                        A method's cognitive complexity is based on a few simple rules:

                                                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                                        • Code is considered more complex for each "break in the linear flow of the code"
                                                        • Code is considered more complex when "flow breaking structures are nested"

                                                        Further reading

                                                        Method get_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/v3/class-wc-api-products.php - About 35 mins to fix

                                                          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/v3/class-wc-api-products.php - About 35 mins to fix

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

                                                                public function create_product_shipping_class( $data ) {
                                                                    global $wpdb;
                                                            
                                                                    try {
                                                                        if ( ! isset( $data['product_shipping_class'] ) ) {
                                                            Severity: Minor
                                                            Found in includes/legacy/api/v3/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 edit_product_attribute_term has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                            Open

                                                                public function edit_product_attribute_term( $attribute_id, $id, $data ) {
                                                                    global $wpdb;
                                                            
                                                                    try {
                                                                        if ( ! isset( $data['product_attribute_term'] ) ) {
                                                            Severity: Minor
                                                            Found in includes/legacy/api/v3/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/v3/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_uploaded_image_as_attachment has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                            Open

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

                                                                public function create_product_attribute_term( $attribute_id, $data ) {
                                                                    global $wpdb;
                                                            
                                                                    try {
                                                                        if ( ! isset( $data['product_attribute_term'] ) ) {
                                                            Severity: Minor
                                                            Found in includes/legacy/api/v3/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 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/v3/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_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/v3/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_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/v3/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_attribute_term has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                            Open

                                                                public function get_product_attribute_term( $attribute_id, $id, $fields = null ) {
                                                                    global $wpdb;
                                                            
                                                                    try {
                                                                        $id = absint( $id );
                                                            Severity: Minor
                                                            Found in includes/legacy/api/v3/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/v3/class-wc-api-products.php and 1 other location - About 3 days to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 960..1040

                                                            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/v3/class-wc-api-products.php and 1 other location - About 2 days to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 2245..2311

                                                            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/v3/class-wc-api-products.php and 1 other location - About 2 days to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1927..1951

                                                            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/v3/class-wc-api-products.php and 1 other location - About 2 days to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 587..633

                                                            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/v3/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 415..470

                                                            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/v3/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1043..1090

                                                            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/v3/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1465..1508

                                                            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/v3/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1574..1627

                                                            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/v3/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1874..1913

                                                            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/v3/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 844..891

                                                            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/v3/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1409..1447

                                                            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

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

                                                                    try {
                                                                        if ( ! isset( $data['product_tag'] ) ) {
                                                                            throw new WC_API_Exception( 'woocommerce_api_missing_product_tag', sprintf( __( 'No %1$s data specified to edit %1$s', 'woocommerce' ), 'product_tag' ), 400 );
                                                                        }
                                                            
                                                            
                                                            Severity: Major
                                                            Found in includes/legacy/api/v3/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 3247..3277

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

                                                            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

                                                                    try {
                                                                        if ( ! isset( $data['product_shipping_class'] ) ) {
                                                                            throw new WC_API_Exception( 'woocommerce_api_missing_product_shipping_class', sprintf( __( 'No %1$s data specified to edit %1$s', 'woocommerce' ), 'product_shipping_class' ), 400 );
                                                                        }
                                                            
                                                            
                                                            Severity: Major
                                                            Found in includes/legacy/api/v3/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 1002..1032

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

                                                            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_uploaded_image_as_attachment( $upload, $id = 0 ) {
                                                                    $info    = wp_check_filetype( $upload['file'] );
                                                                    $title   = '';
                                                                    $content = '';
                                                            
                                                            
                                                            Severity: Major
                                                            Found in includes/legacy/api/v3/class-wc-api-products.php and 1 other location - About 1 day to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1715..1743

                                                            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/v3/class-wc-api-products.php and 1 other location - About 7 hrs to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 518..545

                                                            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/v3/class-wc-api-products.php and 1 other location - About 6 hrs to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1519..1543

                                                            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/v3/class-wc-api-products.php and 1 other location - About 6 hrs to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1837..1862

                                                            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

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

                                                                public function delete_product_shipping_class( $id ) {
                                                                    global $wpdb;
                                                            
                                                                    try {
                                                                        // Check permissions
                                                            Severity: Major
                                                            Found in includes/legacy/api/v3/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 849..870

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

                                                            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 delete_product_category( $id ) {
                                                                    global $wpdb;
                                                            
                                                                    try {
                                                                        // Check permissions
                                                            Severity: Major
                                                            Found in includes/legacy/api/v3/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 3288..3309

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

                                                            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/v3/class-wc-api-products.php and 1 other location - About 6 hrs to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 480..505

                                                            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_shipping_classes( $fields = null ) {
                                                                    try {
                                                                        // Permissions check
                                                                        if ( ! current_user_can( 'manage_product_terms' ) ) {
                                                                            throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_product_shipping_classes', __( 'You do not have permission to read product shipping classes', 'woocommerce' ), 401 );
                                                            Severity: Major
                                                            Found in includes/legacy/api/v3/class-wc-api-products.php and 3 other locations - About 5 hrs to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 556..575
                                                            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

                                                            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

                                                            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/v3/class-wc-api-products.php and 3 other locations - About 5 hrs to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 556..575
                                                            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

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

                                                                public function get_product_tags( $fields = null ) {
                                                                    try {
                                                                        // Permissions check
                                                                        if ( ! current_user_can( 'manage_product_terms' ) ) {
                                                                            throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_product_tags', __( 'You do not have permission to read product tags', 'woocommerce' ), 401 );
                                                            Severity: Major
                                                            Found in includes/legacy/api/v3/class-wc-api-products.php and 3 other locations - About 5 hrs to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 556..575
                                                            includes/legacy/api/v3/class-wc-api-products.php on lines 615..634
                                                            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/v3/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/v2/class-wc-api-products.php on lines 111..135

                                                            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/v3/class-wc-api-products.php and 1 other location - About 3 hrs to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 939..957

                                                            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/v3/class-wc-api-products.php and 1 other location - About 3 hrs to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 182..198

                                                            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/v3/class-wc-api-products.php and 1 other location - About 2 hrs to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1645..1673

                                                            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/v3/class-wc-api-products.php and 1 other location - About 1 hr to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 2003..2013

                                                            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/v3/class-wc-api-products.php and 1 other location - About 1 hr to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 368..370

                                                            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/v3/class-wc-api-products.php and 1 other location - About 1 hr to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1224..1240

                                                            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/v3/class-wc-api-products.php and 1 other location - About 55 mins to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 1337..1352

                                                            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/v3/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/v2/class-wc-api-products.php on lines 1752..1760
                                                            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/v3/class-wc-api-products.php and 1 other location - About 45 mins to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 212..307

                                                            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/v3/class-wc-api-products.php and 1 other location - About 40 mins to fix
                                                            includes/legacy/api/v2/class-wc-api-products.php on lines 673..685

                                                            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