woocommerce/woocommerce

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

Summary

Maintainability
F
2 wks
Test Coverage

Function set_product_meta has a Cognitive Complexity of 110 (exceeds 5 allowed). Consider refactoring.
Open

    protected function set_product_meta( $product, $request ) {
        // Virtual.
        if ( isset( $request['virtual'] ) ) {
            $product->set_virtual( $request['virtual'] );
        }
Severity: Minor
Found in includes/legacy/api/class-wc-rest-legacy-products-controller.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_data has a Cognitive Complexity of 85 (exceeds 5 allowed). Consider refactoring.
Open

    protected function save_variations_data( $product, $request ) {
        foreach ( $request['variations'] as $menu_order => $data ) {
            $variation = new WC_Product_Variation( isset( $data['id'] ) ? absint( $data['id'] ) : 0 );

            // Create initial name and status.
Severity: Minor
Found in includes/legacy/api/class-wc-rest-legacy-products-controller.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 set_product_meta has 197 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function set_product_meta( $product, $request ) {
        // Virtual.
        if ( isset( $request['virtual'] ) ) {
            $product->set_virtual( $request['virtual'] );
        }
Severity: Major
Found in includes/legacy/api/class-wc-rest-legacy-products-controller.php - About 7 hrs to fix

    File class-wc-rest-legacy-products-controller.php has 471 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /**
     * REST API Legacy Products controller
     *
     * Handles requests to the /products endpoint.
    Severity: Minor
    Found in includes/legacy/api/class-wc-rest-legacy-products-controller.php - About 7 hrs to fix

      Method save_variations_data has 115 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function save_variations_data( $product, $request ) {
              foreach ( $request['variations'] as $menu_order => $data ) {
                  $variation = new WC_Product_Variation( isset( $data['id'] ) ? absint( $data['id'] ) : 0 );
      
                  // Create initial name and status.
      Severity: Major
      Found in includes/legacy/api/class-wc-rest-legacy-products-controller.php - About 4 hrs to fix

        Method query_args has 79 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function query_args( $args, $request ) {
                // Set post_status.
                $args['post_status'] = $request['status'];
        
                // Taxonomy query to filter products by type, category,
        Severity: Major
        Found in includes/legacy/api/class-wc-rest-legacy-products-controller.php - About 3 hrs to fix

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

              public function query_args( $args, $request ) {
                  // Set post_status.
                  $args['post_status'] = $request['status'];
          
                  // Taxonomy query to filter products by type, category,
          Severity: Minor
          Found in includes/legacy/api/class-wc-rest-legacy-products-controller.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

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

              protected function save_variations_data( $product, $request ) {
                  foreach ( $request['variations'] as $menu_order => $data ) {
                      $variation = new WC_Product_Variation( isset( $data['id'] ) ? absint( $data['id'] ) : 0 );
          
                      // Create initial name and status.
          includes/rest-api/Controllers/Version1/class-wc-rest-products-v1-controller.php on lines 1365..1539

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

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

                  if ( isset( $request['attributes'] ) ) {
                      $attributes = array();
          
                      foreach ( $request['attributes'] as $attribute ) {
                          $attribute_id   = 0;
          includes/rest-api/Controllers/Version1/class-wc-rest-products-v1-controller.php on lines 1117..1180
          includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php on lines 987..1050
          includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php on lines 401..464

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

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

                  if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) {
                      // Manage stock.
                      if ( isset( $request['manage_stock'] ) ) {
                          $product->set_manage_stock( $request['manage_stock'] );
                      }
          includes/rest-api/Controllers/Version1/class-wc-rest-products-v1-controller.php on lines 1227..1270
          includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php on lines 1105..1148
          includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php on lines 519..562

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

          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' ), true ) ) {
                      $product->set_regular_price( '' );
                      $product->set_sale_price( '' );
                      $product->set_date_on_sale_to( '' );
                      $product->set_date_on_sale_from( '' );
          includes/rest-api/Controllers/Version1/class-wc-rest-products-v1-controller.php on lines 1183..1207

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

          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 update_post_meta_fields( $post, $request ) {
                  $product = wc_get_product( $post );
          
                  // Check for featured/gallery images, upload it and set it.
                  if ( isset( $request['images'] ) ) {
          includes/rest-api/Controllers/Version1/class-wc-rest-products-v1-controller.php on lines 1559..1585

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

          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 delete_post( $id ) {
                  if ( ! empty( $id->ID ) ) {
                      $id = $id->ID;
                  } elseif ( ! is_numeric( $id ) || 0 >= $id ) {
                      return;
          includes/rest-api/Controllers/Version1/class-wc-rest-products-v1-controller.php on lines 1601..1622

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

          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

                  if ( ! empty( $request['sku'] ) ) {
                      $skus = explode( ',', $request['sku'] );
                      // Include the current string as a SKU too.
                      if ( 1 < count( $skus ) ) {
                          $skus[] = $request['sku'];
          includes/rest-api/Controllers/Version1/class-wc-rest-products-v1-controller.php on lines 192..204
          includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php on lines 264..279
          includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller.php on lines 769..784
          includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php on lines 148..163

          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

          There are no issues that match your filters.

          Category
          Status