woothemes/woocommerce

View on GitHub
includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php

Summary

Maintainability
F
3 wks
Test Coverage

Method get_item_schema has 844 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function get_item_schema() {
        $schema = array(
            '$schema'    => 'http://json-schema.org/draft-04/schema#',
            'title'      => $this->post_type,
            'type'       => 'object',

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

    <?php
    /**
     * REST API Orders controller
     *
     * Handles requests to the /orders endpoint.

      Function prepare_object_for_database has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function prepare_object_for_database( $request, $creating = false ) {
              $id        = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
              $order     = new WC_Order( $id );
              $schema    = $this->get_item_schema();
              $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );

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

          protected function get_formatted_item_data( $order ) {
              $extra_fields      = array( 'meta_data', 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines', 'refunds' );
              $format_decimal    = array( 'discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax' );
              $format_date       = array( 'date_created', 'date_modified', 'date_completed', 'date_paid' );
              // These fields are dependent on other fields.

        Method register_routes has 71 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function register_routes() {
                register_rest_route(
                    $this->namespace,
                    '/' . $this->rest_base,
                    array(

          WC_REST_Orders_V2_Controller has 25 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class WC_REST_Orders_V2_Controller extends WC_REST_CRUD_Controller {
          
              /**
               * Endpoint namespace.
               *

            Function get_formatted_item_data has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function get_formatted_item_data( $order ) {
                    $extra_fields      = array( 'meta_data', 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines', 'refunds' );
                    $format_decimal    = array( 'discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax' );
                    $format_date       = array( 'date_created', 'date_modified', 'date_completed', 'date_paid' );
                    // These fields are dependent on other fields.

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

                protected function save_object( $request, $creating = false ) {
                    try {
                        $object = $this->prepare_object_for_database( $request, $creating );
            
                        if ( is_wp_error( $object ) ) {

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

                protected function prepare_object_for_database( $request, $creating = false ) {
                    $id        = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
                    $order     = new WC_Order( $id );
                    $schema    = $this->get_item_schema();
                    $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );

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

                  protected function get_order_item_data( $item ) {
                      $data           = $item->get_data();
                      $format_decimal = array( 'subtotal', 'subtotal_tax', 'total', 'total_tax', 'tax_total', 'shipping_tax_total' );
              
                      // Format decimal values.

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

                    protected function get_order_item_data( $item ) {
                        $data           = $item->get_data();
                        $format_decimal = array( 'subtotal', 'subtotal_tax', 'total', 'total_tax', 'tax_total', 'shipping_tax_total' );
                
                        // Format decimal values.

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

                    protected function prepare_objects_query( $request ) {
                        global $wpdb;
                
                        $args = parent::prepare_objects_query( $request );
                
                

                  Method save_object has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function save_object( $request, $creating = false ) {
                          try {
                              $object = $this->prepare_object_for_database( $request, $creating );
                  
                              if ( is_wp_error( $object ) ) {

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

                        public function get_collection_params() {
                            $params = parent::get_collection_params();
                    
                            $params['status']   = array(
                                'default'           => 'any',

                      Function prepare_objects_query has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                          protected function prepare_objects_query( $request ) {
                              global $wpdb;
                      
                              $args = parent::prepare_objects_query( $request );
                      
                      

                      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

                      Consider simplifying this complex logical expression.
                      Open

                                      if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) {
                                          $object->calculate_totals( true );
                                      }

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

                            protected function maybe_set_item_meta_data( $item, $posted ) {
                                if ( ! empty( $posted['meta_data'] ) && is_array( $posted['meta_data'] ) ) {
                                    foreach ( $posted['meta_data'] as $meta ) {
                                        if ( isset( $meta['key'] ) ) {
                                            $value = isset( $meta['value'] ) ? $meta['value'] : null;

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

                            protected function set_item( $order, $item_type, $posted ) {
                                global $wpdb;
                        
                                if ( ! empty( $posted['id'] ) ) {
                                    $action = 'update';

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

                            protected function get_product_id( $posted, $action = 'create' ) {
                                if ( ! empty( $posted['sku'] ) ) {
                                    $product_id = (int) wc_get_product_id_by_sku( $posted['sku'] );
                                } elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) {
                                    $product_id = (int) $posted['product_id'];

                        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() {
                                register_rest_route(
                                    $this->namespace,
                                    '/' . $this->rest_base,
                                    array(
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 56..118
                        includes/rest-api/Controllers/Version1/class-wc-rest-taxes-v1-controller.php on lines 42..104

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

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

                                        'billing'              => array(
                                            'description' => __( 'Billing address.', 'woocommerce' ),
                                            'type'        => 'object',
                                            'context'     => array( 'view', 'edit' ),
                                            'properties'  => array(
                        includes/rest-api/Controllers/Version1/class-wc-rest-customers-v1-controller.php on lines 722..784
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1029..1091
                        includes/rest-api/Controllers/Version2/class-wc-rest-customers-v2-controller.php on lines 194..256
                        includes/rest-api/Controllers/Version3/class-wc-rest-customers-controller.php on lines 149..211

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

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

                                        'shipping'             => array(
                                            'description' => __( 'Shipping address.', 'woocommerce' ),
                                            'type'        => 'object',
                                            'context'     => array( 'view', 'edit' ),
                                            'properties'  => array(
                        includes/rest-api/Controllers/Version1/class-wc-rest-customers-v1-controller.php on lines 785..836
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1092..1143
                        includes/rest-api/Controllers/Version2/class-wc-rest-customers-v2-controller.php on lines 257..308
                        includes/rest-api/Controllers/Version3/class-wc-rest-customers-controller.php on lines 212..263

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

                        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

                            protected function prepare_links( $object, $request ) {
                                $links = array(
                                    'self'       => array(
                                        'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ),
                                    ),
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 367..387

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

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

                                        'refunds'              => array(
                                            'description' => __( 'List of refunds.', 'woocommerce' ),
                                            'type'        => 'array',
                                            'context'     => array( 'view', 'edit' ),
                                            'readonly'    => true,
                        includes/rest-api/Controllers/Version1/class-wc-rest-order-refunds-v1-controller.php on lines 445..473
                        includes/rest-api/Controllers/Version1/class-wc-rest-order-refunds-v1-controller.php on lines 474..502
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1281..1309
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1310..1338
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1494..1522
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1558..1586
                        includes/rest-api/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php on lines 494..522
                        includes/rest-api/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php on lines 523..551
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1632..1660

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

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

                                                    'taxes'      => array(
                                                        'description' => __( 'Line taxes.', 'woocommerce' ),
                                                        'type'        => 'array',
                                                        'context'     => array( 'view', 'edit' ),
                                                        'readonly'    => true,
                        includes/rest-api/Controllers/Version1/class-wc-rest-order-refunds-v1-controller.php on lines 445..473
                        includes/rest-api/Controllers/Version1/class-wc-rest-order-refunds-v1-controller.php on lines 474..502
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1281..1309
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1310..1338
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1494..1522
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1558..1586
                        includes/rest-api/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php on lines 494..522
                        includes/rest-api/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php on lines 523..551
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1748..1776

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

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

                                                    'meta_data'          => array(
                                                        'description' => __( 'Meta data.', 'woocommerce' ),
                                                        'type'        => 'array',
                                                        'context'     => array( 'view', 'edit' ),
                                                        'items'       => array(
                        includes/rest-api/Controllers/Version2/class-wc-rest-coupons-v2-controller.php on lines 494..519
                        includes/rest-api/Controllers/Version2/class-wc-rest-customers-v2-controller.php on lines 333..358
                        includes/rest-api/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php on lines 400..425
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1254..1279
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1563..1588
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1661..1686
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1719..1744
                        includes/rest-api/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php on lines 965..990
                        includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php on lines 2240..2265
                        includes/rest-api/Controllers/Version3/class-wc-rest-customers-controller.php on lines 276..301
                        includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller.php on lines 724..749
                        includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php on lines 1303..1328

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

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

                                        'meta_data'            => array(
                                            'description' => __( 'Meta data.', 'woocommerce' ),
                                            'type'        => 'array',
                                            'context'     => array( 'view', 'edit' ),
                                            'items'       => array(
                        includes/rest-api/Controllers/Version2/class-wc-rest-coupons-v2-controller.php on lines 494..519
                        includes/rest-api/Controllers/Version2/class-wc-rest-customers-v2-controller.php on lines 333..358
                        includes/rest-api/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php on lines 400..425
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1472..1497
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1563..1588
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1661..1686
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1719..1744
                        includes/rest-api/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php on lines 965..990
                        includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php on lines 2240..2265
                        includes/rest-api/Controllers/Version3/class-wc-rest-customers-controller.php on lines 276..301
                        includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller.php on lines 724..749
                        includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php on lines 1303..1328

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

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

                                                    'meta_data'  => array(
                                                        'description' => __( 'Meta data.', 'woocommerce' ),
                                                        'type'        => 'array',
                                                        'context'     => array( 'view', 'edit' ),
                                                        'items'       => array(
                        includes/rest-api/Controllers/Version2/class-wc-rest-coupons-v2-controller.php on lines 494..519
                        includes/rest-api/Controllers/Version2/class-wc-rest-customers-v2-controller.php on lines 333..358
                        includes/rest-api/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php on lines 400..425
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1254..1279
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1472..1497
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1563..1588
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1719..1744
                        includes/rest-api/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php on lines 965..990
                        includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php on lines 2240..2265
                        includes/rest-api/Controllers/Version3/class-wc-rest-customers-controller.php on lines 276..301
                        includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller.php on lines 724..749
                        includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php on lines 1303..1328

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

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

                                                    'meta_data'    => array(
                                                        'description' => __( 'Meta data.', 'woocommerce' ),
                                                        'type'        => 'array',
                                                        'context'     => array( 'view', 'edit' ),
                                                        'items'       => array(
                        includes/rest-api/Controllers/Version2/class-wc-rest-coupons-v2-controller.php on lines 494..519
                        includes/rest-api/Controllers/Version2/class-wc-rest-customers-v2-controller.php on lines 333..358
                        includes/rest-api/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php on lines 400..425
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1254..1279
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1472..1497
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1563..1588
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1661..1686
                        includes/rest-api/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php on lines 965..990
                        includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php on lines 2240..2265
                        includes/rest-api/Controllers/Version3/class-wc-rest-customers-controller.php on lines 276..301
                        includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller.php on lines 724..749
                        includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php on lines 1303..1328

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

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

                                                    'meta_data'    => array(
                                                        'description' => __( 'Meta data.', 'woocommerce' ),
                                                        'type'        => 'array',
                                                        'context'     => array( 'view', 'edit' ),
                                                        'items'       => array(
                        includes/rest-api/Controllers/Version2/class-wc-rest-coupons-v2-controller.php on lines 494..519
                        includes/rest-api/Controllers/Version2/class-wc-rest-customers-v2-controller.php on lines 333..358
                        includes/rest-api/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php on lines 400..425
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1254..1279
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1472..1497
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1661..1686
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1719..1744
                        includes/rest-api/Controllers/Version2/class-wc-rest-product-variations-v2-controller.php on lines 965..990
                        includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php on lines 2240..2265
                        includes/rest-api/Controllers/Version3/class-wc-rest-customers-controller.php on lines 276..301
                        includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller.php on lines 724..749
                        includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php on lines 1303..1328

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

                        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

                            protected function prepare_shipping_lines( $posted, $action = 'create', $item = null ) {
                                $item = is_null( $item ) ? new WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
                        
                                if ( 'create' === $action ) {
                                    if ( empty( $posted['method_id'] ) ) {
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 819..832

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

                        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

                            protected function prepare_fee_lines( $posted, $action = 'create', $item = null ) {
                                $item = is_null( $item ) ? new WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
                        
                                if ( 'create' === $action ) {
                                    if ( empty( $posted['name'] ) ) {
                        includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 795..808

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

                        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

                                                    'taxes'        => array(
                                                        'description' => __( 'Line taxes.', 'woocommerce' ),
                                                        'type'        => 'array',
                                                        'context'     => array( 'view', 'edit' ),
                                                        'readonly'    => true,
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1429..1451

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

                        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 get_product_id( $posted, $action = 'create' ) {
                                if ( ! empty( $posted['sku'] ) ) {
                                    $product_id = (int) wc_get_product_id_by_sku( $posted['sku'] );
                                } elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) {
                                    $product_id = (int) $posted['product_id'];
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 613..626

                        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 ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] ) {
                                        // Make sure customer exists.
                                        if ( false === get_user_by( 'id', $request['customer_id'] ) ) {
                                            throw new WC_REST_Exception( 'woocommerce_rest_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce' ), 400 );
                                        }
                        includes/rest-api/Controllers/Version3/class-wc-rest-orders-controller.php on lines 159..169

                        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

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

                                $allowed_fields = array(
                                    'id',
                                    'parent_id',
                                    'number',
                                    'order_key',
                        includes/gateways/paypal/class-wc-gateway-paypal.php on lines 176..176

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

                        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 ( $creating ) {
                                        $object->set_created_via( 'rest-api' );
                                        $object->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
                                        $object->calculate_totals();
                                    } else {
                        includes/rest-api/Controllers/Version3/class-wc-rest-orders-controller.php on lines 171..180

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

                        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

                                            case 'coupon_lines':
                                                if ( is_array( $value ) ) {
                                                    foreach ( $value as $item ) {
                                                        if ( is_array( $item ) ) {
                                                            if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) {
                        includes/legacy/api/class-wc-rest-legacy-orders-controller.php on lines 184..196
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 471..483
                        includes/rest-api/Controllers/Version3/class-wc-rest-orders-controller.php on lines 97..109

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

                                if ( $product && $product !== $item->get_product() ) {
                                    $item->set_product( $product );
                        
                                    if ( 'create' === $action ) {
                                        $quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1;
                        includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 665..674

                        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