woocommerce/woocommerce

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

Summary

Maintainability
F
1 wk
Test Coverage

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

    public function filter_response_fields( $data, $resource, $fields ) {

        if ( ! is_array( $data ) || empty( $fields ) ) {
            return $data;
        }
Severity: Minor
Found in includes/legacy/api/v2/class-wc-api-resource.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

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

    protected function merge_query_args( $base_args, $request_args ) {

        $args = array();

        // date
Severity: Minor
Found in includes/legacy/api/v2/class-wc-api-resource.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

Function validate_request has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    protected function validate_request( $id, $type, $context ) {

        if ( 'shop_order' === $type || 'shop_coupon' === $type || 'shop_webhook' === $type ) {
            $resource_name = str_replace( 'shop_', '', $type );
        } else {
Severity: Minor
Found in includes/legacy/api/v2/class-wc-api-resource.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

Function maybe_add_meta has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    public function maybe_add_meta( $data, $resource ) {

        if ( isset( $this->server->params['GET']['filter']['meta'] ) && 'true' === $this->server->params['GET']['filter']['meta'] && is_object( $resource ) ) {

            // don't attempt to add meta more than once
Severity: Minor
Found in includes/legacy/api/v2/class-wc-api-resource.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 merge_query_args has 49 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function merge_query_args( $base_args, $request_args ) {

        $args = array();

        // date
Severity: Minor
Found in includes/legacy/api/v2/class-wc-api-resource.php - About 1 hr to fix

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

        protected function delete( $id, $type, $force = false ) {
    
            if ( 'shop_order' === $type || 'shop_coupon' === $type ) {
                $resource_name = str_replace( 'shop_', '', $type );
            } else {
    Severity: Minor
    Found in includes/legacy/api/v2/class-wc-api-resource.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 validate_request has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function validate_request( $id, $type, $context ) {
    
            if ( 'shop_order' === $type || 'shop_coupon' === $type || 'shop_webhook' === $type ) {
                $resource_name = str_replace( 'shop_', '', $type );
            } else {
    Severity: Minor
    Found in includes/legacy/api/v2/class-wc-api-resource.php - About 1 hr to fix

      Method maybe_add_meta has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function maybe_add_meta( $data, $resource ) {
      
              if ( isset( $this->server->params['GET']['filter']['meta'] ) && 'true' === $this->server->params['GET']['filter']['meta'] && is_object( $resource ) ) {
      
                  // don't attempt to add meta more than once
      Severity: Minor
      Found in includes/legacy/api/v2/class-wc-api-resource.php - About 1 hr to fix

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

            private function check_permission( $post, $context ) {
        
                if ( ! is_a( $post, 'WP_Post' ) ) {
                    $post = get_post( $post );
                }
        Severity: Minor
        Found in includes/legacy/api/v2/class-wc-api-resource.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

        Avoid too many return statements within this method.
        Open

                    return false;
        Severity: Major
        Found in includes/legacy/api/v2/class-wc-api-resource.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return $id;
          Severity: Major
          Found in includes/legacy/api/v2/class-wc-api-resource.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                                    return new WP_Error( "woocommerce_api_user_cannot_edit_{$resource_name}", sprintf( __( 'You do not have permission to edit this %s', 'woocommerce' ), $resource_name ), array( 'status' => 401 ) );
            Severity: Major
            Found in includes/legacy/api/v2/class-wc-api-resource.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                              return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), $resource_name ) );
              Severity: Major
              Found in includes/legacy/api/v2/class-wc-api-resource.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                        return new WP_Error( "woocommerce_api_user_cannot_delete_{$resource_name}", sprintf( __( 'You do not have permission to delete this %s', 'woocommerce' ), $resource_name ), array( 'status' => 401 ) );
                Severity: Major
                Found in includes/legacy/api/v2/class-wc-api-resource.php - About 30 mins to fix

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

                      protected function merge_query_args( $base_args, $request_args ) {
                  
                          $args = array();
                  
                          // date
                  Severity: Major
                  Found in includes/legacy/api/v2/class-wc-api-resource.php and 1 other location - About 3 days to fix
                  includes/legacy/api/v3/class-wc-api-resource.php on lines 150..234

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

                  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_request( $id, $type, $context ) {
                  
                          if ( 'shop_order' === $type || 'shop_coupon' === $type || 'shop_webhook' === $type ) {
                              $resource_name = str_replace( 'shop_', '', $type );
                          } else {
                  Severity: Major
                  Found in includes/legacy/api/v2/class-wc-api-resource.php and 1 other location - About 2 days to fix
                  includes/legacy/api/v3/class-wc-api-resource.php on lines 84..140

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

                  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

                      protected function delete( $id, $type, $force = false ) {
                  
                          if ( 'shop_order' === $type || 'shop_coupon' === $type ) {
                              $resource_name = str_replace( 'shop_', '', $type );
                          } else {
                  Severity: Major
                  Found in includes/legacy/api/v2/class-wc-api-resource.php and 2 other locations - About 1 day to fix
                  includes/legacy/api/v1/class-wc-api-resource.php on lines 300..336
                  includes/legacy/api/v3/class-wc-api-resource.php on lines 361..397

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

                  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 maybe_add_meta( $data, $resource ) {
                  
                          if ( isset( $this->server->params['GET']['filter']['meta'] ) && 'true' === $this->server->params['GET']['filter']['meta'] && is_object( $resource ) ) {
                  
                              // don't attempt to add meta more than once
                  Severity: Major
                  Found in includes/legacy/api/v2/class-wc-api-resource.php and 2 other locations - About 1 day to fix
                  includes/legacy/api/v1/class-wc-api-resource.php on lines 184..234
                  includes/legacy/api/v3/class-wc-api-resource.php on lines 245..295

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

                  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 filter_response_fields( $data, $resource, $fields ) {
                  
                          if ( ! is_array( $data ) || empty( $fields ) ) {
                              return $data;
                          }
                  Severity: Major
                  Found in includes/legacy/api/v2/class-wc-api-resource.php and 2 other locations - About 7 hrs to fix
                  includes/legacy/api/v1/class-wc-api-resource.php on lines 245..289
                  includes/legacy/api/v3/class-wc-api-resource.php on lines 306..350

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

                  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