woocommerce/woocommerce

View on GitHub
includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php

Summary

Maintainability
F
3 days
Test Coverage

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

<?php
/**
 * Abstract Rest CRUD Controller Class
 *
 * @class    WC_REST_CRUD_Controller

    Method get_collection_params has 104 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function get_collection_params() {
            $params                       = array();
            $params['context']            = $this->get_context_param();
            $params['context']['default'] = 'view';
    
    

      Method get_items has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function get_items( $request ) {
              $query_args    = $this->prepare_objects_query( $request );
              $query_results = $this->get_objects( $query_args );
      
              $objects = array();

        Function delete_item has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public function delete_item( $request ) {
                $force  = (bool) $request['force'];
                $object = $this->get_object( (int) $request['id'] );
                $result = false;
        
        

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

            public function get_items( $request ) {
                $query_args    = $this->prepare_objects_query( $request );
                $query_results = $this->get_objects( $query_args );
        
                $objects = array();

        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 delete_item has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function delete_item( $request ) {
                $force  = (bool) $request['force'];
                $object = $this->get_object( (int) $request['id'] );
                $result = false;
        
        

          Method prepare_objects_query has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function prepare_objects_query( $request ) {
                  $args                        = array();
                  $args['offset']              = $request['offset'];
                  $args['order']               = $request['order'];
                  $args['orderby']             = $request['orderby'];

            Avoid too many return statements within this method.
            Open

                    return rest_ensure_response( $response );
            Severity: Major
            Found in includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $response;
              Severity: Major
              Found in includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
                Severity: Major
                Found in includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return $response;
                  Severity: Major
                  Found in includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php - About 30 mins to fix

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

                            if ( $force ) {
                                $object->delete( true );
                                $result = 0 === $object->get_id();
                            } else {
                                // If we don't support trashing for this type, error out.
                    includes/rest-api/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php on lines 522..550

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

                    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 ( $this->hierarchical ) {
                                $params['parent'] = array(
                                    'description'       => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
                                    'type'              => 'array',
                                    'items'             => array(
                    includes/rest-api/Controllers/Version3/class-wc-rest-posts-controller.php on lines 683..702

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

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

                        public function delete_item_permissions_check( $request ) {
                            $object = $this->get_object( (int) $request['id'] );
                    
                            if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
                                return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
                    includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php on lines 52..60
                    includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php on lines 68..76

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

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

                        public function update_item_permissions_check( $request ) {
                            $object = $this->get_object( (int) $request['id'] );
                    
                            if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) {
                                return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
                    includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php on lines 52..60
                    includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php on lines 84..92

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

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

                        public function get_item_permissions_check( $request ) {
                            $object = $this->get_object( (int) $request['id'] );
                    
                            if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'read', $object->get_id() ) ) {
                                return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
                    includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php on lines 68..76
                    includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php on lines 84..92

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

                    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