woothemes/woocommerce

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

Summary

Maintainability
D
2 days
Test Coverage

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

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

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

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

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

              private function get_images( $product ) {
                  $images        = $attachment_ids = array();
                  $product_image = $product->get_image_id();
          
                  // Add featured image.
          Severity: Minor
          Found in includes/legacy/api/v1/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_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/v1/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 3 locations. Consider refactoring.
          Open

              public function register_routes( $routes ) {
          
                  # GET /products
                  $routes[ $this->base ] = array(
                      array( array( $this, 'get_products' ),     WC_API_Server::READABLE ),
          Severity: Major
          Found in includes/legacy/api/v1/class-wc-api-products.php and 2 other locations - About 3 hrs to fix
          includes/legacy/api/v1/class-wc-api-coupons.php on lines 34..57
          includes/legacy/api/v1/class-wc-api-customers.php on lines 58..81

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

          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/v1/class-wc-api-products.php and 2 other locations - About 3 hrs to fix
          includes/legacy/api/v2/class-wc-api-products.php on lines 111..135
          includes/legacy/api/v3/class-wc-api-products.php on lines 148..172

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 154.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 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/v1/class-wc-api-products.php and 4 other locations - About 55 mins to fix
          includes/legacy/api/v2/class-wc-api-products.php on lines 1752..1760
          includes/legacy/api/v3/class-wc-api-products.php on lines 2305..2313
          includes/rest-api/Controllers/Version1/class-wc-rest-products-v1-controller.php on lines 372..380
          includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php on lines 526..540

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 98.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status