woothemes/woocommerce

View on GitHub

Showing 4,341 of 4,341 total issues

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

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

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

        public function create_order_refund( $order_id, $data, $api_refund = true ) {
            try {
                if ( ! isset( $data['order_refund'] ) ) {
                    throw new WC_API_Exception( 'woocommerce_api_missing_order_refund_data', sprintf( __( 'No %1$s data specified to create %1$s', 'woocommerce' ), 'order_refund' ), 400 );
                }
    Severity: Major
    Found in includes/legacy/api/v2/class-wc-api-orders.php and 1 other location - About 3 days to fix
    includes/legacy/api/v3/class-wc-api-orders.php on lines 1621..1689

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

    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

        public function create_order_refund( $order_id, $data, $api_refund = true ) {
            try {
                if ( ! isset( $data['order_refund'] ) ) {
                    throw new WC_API_Exception( 'woocommerce_api_missing_order_refund_data', sprintf( __( 'No %1$s data specified to create %1$s', 'woocommerce' ), 'order_refund' ), 400 );
                }
    Severity: Major
    Found in includes/legacy/api/v3/class-wc-api-orders.php and 1 other location - About 3 days to fix
    includes/legacy/api/v2/class-wc-api-orders.php on lines 1576..1644

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

    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

    Method get_country_locale has 649 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function get_country_locale() {
            if ( empty( $this->locale ) ) {
                $this->locale = apply_filters(
                    'woocommerce_get_country_locale',
                    array(
    Severity: Major
    Found in includes/class-wc-countries.php - About 3 days to fix

      Function PhotoSwipeUI_Default has 641 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

       function(pswp, framework) {
      
          var ui = this;
          var _overlayUIUpdated = false,
              _controlsVisible = true,
      Severity: Major
      Found in assets/js/photoswipe/photoswipe-ui-default.js - About 3 days to fix

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

            public function dispatch() {
        
                switch ( $this->method ) {
        
                    case 'HEAD' :
        Severity: Major
        Found in includes/legacy/api/v3/class-wc-api-server.php and 2 other locations - About 3 days to fix
        includes/legacy/api/v1/class-wc-api-server.php on lines 295..378
        includes/legacy/api/v2/class-wc-api-server.php on lines 293..376

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

        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 dispatch() {
        
                switch ( $this->method ) {
        
                    case 'HEAD':
        Severity: Major
        Found in includes/legacy/api/v1/class-wc-api-server.php and 2 other locations - About 3 days to fix
        includes/legacy/api/v2/class-wc-api-server.php on lines 293..376
        includes/legacy/api/v3/class-wc-api-server.php on lines 293..376

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

        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 dispatch() {
        
                switch ( $this->method ) {
        
                    case 'HEAD' :
        Severity: Major
        Found in includes/legacy/api/v2/class-wc-api-server.php and 2 other locations - About 3 days to fix
        includes/legacy/api/v1/class-wc-api-server.php on lines 295..378
        includes/legacy/api/v3/class-wc-api-server.php on lines 293..376

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

        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

        File meta-boxes-order.js has 1228 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        // eslint-disable-next-line max-len
        /*global woocommerce_admin_meta_boxes, woocommerce_admin, accounting, woocommerce_admin_meta_boxes_order, wcSetClipboard, wcClearClipboard */
        jQuery( function ( $ ) {
        
            // Stand-in wcTracks.recordEvent in case tracks is not available (for any reason).
        Severity: Major
        Found in assets/js/admin/meta-boxes-order.js - About 3 days to fix

          WC_Product has 158 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class WC_Product extends WC_Abstract_Legacy_Product {
          
              /**
               * This is the name of this object type.
               *
          Severity: Major
          Found in includes/abstracts/abstract-wc-product.php - About 3 days to fix

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

                protected function prepare_object_for_database( $request, $creating = false ) {
                    $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
            
                    // Type is the most important part here because we need to be using the correct class and methods.
                    if ( isset( $request['type'] ) ) {

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

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

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

            Duplicated Code

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

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

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

            Tuning

            This issue has a mass of 593.

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

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

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

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

            Refactorings

            Further Reading

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

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

            Duplicated Code

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

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

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

            Tuning

            This issue has a mass of 593.

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

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

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

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

            Refactorings

            Further Reading

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

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

            Duplicated Code

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

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

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

            Tuning

            This issue has a mass of 593.

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

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

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

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

            Refactorings

            Further Reading

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

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

            Duplicated Code

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

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

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

            Tuning

            This issue has a mass of 593.

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

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

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

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

            Refactorings

            Further Reading

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

                public function get_item_schema() {
                    $weight_unit    = get_option( 'woocommerce_weight_unit' );
                    $dimension_unit = get_option( 'woocommerce_dimension_unit' );
                    $schema         = array(
                        '$schema'    => 'http://json-schema.org/draft-04/schema#',

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

                  public function get_item_schema() {
                      $weight_unit    = get_option( 'woocommerce_weight_unit' );
                      $dimension_unit = get_option( 'woocommerce_dimension_unit' );
                      $schema         = array(
                          '$schema'    => 'http://json-schema.org/draft-04/schema#',

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

                    public function register_routes( $routes ) {
                
                        # GET|POST /orders
                        $routes[ $this->base ] = array(
                            array( array( $this, 'get_orders' ),     WC_API_Server::READABLE ),
                Severity: Major
                Found in includes/legacy/api/v3/class-wc-api-orders.php and 1 other location - About 3 days to fix
                includes/legacy/api/v2/class-wc-api-orders.php on lines 37..94

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

                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

                    public function register_routes( $routes ) {
                
                        # GET|POST /orders
                        $routes[ $this->base ] = array(
                            array( array( $this, 'get_orders' ),     WC_API_Server::READABLE ),
                Severity: Major
                Found in includes/legacy/api/v2/class-wc-api-orders.php and 1 other location - About 3 days to fix
                includes/legacy/api/v3/class-wc-api-orders.php on lines 37..94

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

                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

                Function save_product_meta has a Cognitive Complexity of 147 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function save_product_meta( $product, $data ) {
                        global $wpdb;
                
                        // Virtual.
                        if ( isset( $data['virtual'] ) ) {
                Severity: Minor
                Found in includes/legacy/api/v3/class-wc-api-products.php - About 2 days to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Severity
                Category
                Status
                Source
                Language