woothemes/woocommerce

View on GitHub
includes/admin/class-wc-admin-post-types.php

Summary

Maintainability
F
6 days
Test Coverage

File class-wc-admin-post-types.php has 610 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Post Types Admin
 *
 * @package  WooCommerce\Admin
Severity: Major
Found in includes/admin/class-wc-admin-post-types.php - About 1 day to fix

    Function bulk_edit_save has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

        public function bulk_edit_save( $post_id, $product ) {
            // phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash
    
            $request_data = $this->request_data();
    
    
    Severity: Minor
    Found in includes/admin/class-wc-admin-post-types.php - About 6 hrs to fix

    Cognitive Complexity

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

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

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

    Further reading

    Function quick_edit_save has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

        private function quick_edit_save( $post_id, $product ) {
            $request_data = $this->request_data();
    
            $data_store        = $product->get_data_store();
            $old_regular_price = $product->get_regular_price();
    Severity: Minor
    Found in includes/admin/class-wc-admin-post-types.php - About 5 hrs to fix

    Cognitive Complexity

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

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

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

    Further reading

    Method bulk_edit_save has 98 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function bulk_edit_save( $post_id, $product ) {
            // phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash
    
            $request_data = $this->request_data();
    
    
    Severity: Major
    Found in includes/admin/class-wc-admin-post-types.php - About 3 hrs to fix

      Method quick_edit_save has 81 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function quick_edit_save( $post_id, $product ) {
              $request_data = $this->request_data();
      
              $data_store        = $product->get_data_store();
              $old_regular_price = $product->get_regular_price();
      Severity: Major
      Found in includes/admin/class-wc-admin-post-types.php - About 3 hrs to fix

        WC_Admin_Post_Types has 27 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class WC_Admin_Post_Types {
        
            /**
             * Constructor.
             */
        Severity: Minor
        Found in includes/admin/class-wc-admin-post-types.php - About 3 hrs to fix

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

              private function set_new_price( $product, $price_type ) {
                  // phpcs:disable WordPress.Security.NonceVerification.Recommended
          
                  $request_data = $this->request_data();
          
          
          Severity: Minor
          Found in includes/admin/class-wc-admin-post-types.php - About 2 hrs to fix

          Cognitive Complexity

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

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

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

          Further reading

          Method post_updated_messages has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function post_updated_messages( $messages ) {
                  global $post;
          
                  $messages['product'] = array(
                      0  => '', // Unused. Messages start at index 1.
          Severity: Major
          Found in includes/admin/class-wc-admin-post-types.php - About 2 hrs to fix

            Method set_new_price has 51 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function set_new_price( $product, $price_type ) {
                    // phpcs:disable WordPress.Security.NonceVerification.Recommended
            
                    $request_data = $this->request_data();
            
            
            Severity: Major
            Found in includes/admin/class-wc-admin-post-types.php - About 2 hrs to fix

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

                  private function maybe_update_stock_status( $product, $stock_status ) {
                      if ( $product->is_type( 'external' ) ) {
                          // External products are always in stock.
                          $product->set_stock_status( 'instock' );
                      } elseif ( isset( $stock_status ) ) {
              Severity: Minor
              Found in includes/admin/class-wc-admin-post-types.php - About 1 hr to fix

              Cognitive Complexity

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

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

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

              Further reading

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

                  public function product_data_visibility() {
                      global $post, $thepostid, $product_object;
              
                      if ( 'product' !== $post->post_type ) {
                          return;
              Severity: Minor
              Found in includes/admin/class-wc-admin-post-types.php - About 1 hr to fix

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

                    public function setup_screen() {
                        global $wc_list_table;
                
                        $request_data = $this->request_data();
                
                
                Severity: Minor
                Found in includes/admin/class-wc-admin-post-types.php - About 1 hr to fix

                  Function setup_screen has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function setup_screen() {
                          global $wc_list_table;
                  
                          $request_data = $this->request_data();
                  
                  
                  Severity: Minor
                  Found in includes/admin/class-wc-admin-post-types.php - About 25 mins to fix

                  Cognitive Complexity

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

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

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

                  Further reading

                  Function bulk_and_quick_edit_save_post has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function bulk_and_quick_edit_save_post( $post_id, $post ) {
                          $request_data = $this->request_data();
                  
                          // If this is an autosave, our form has not been submitted, so we don't want to do anything.
                          if ( Constants::is_true( 'DOING_AUTOSAVE' ) ) {
                  Severity: Minor
                  Found in includes/admin/class-wc-admin-post-types.php - About 25 mins to fix

                  Cognitive Complexity

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

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

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

                  Further reading

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

                          $bulk_messages['product'] = array(
                              /* translators: %s: product count */
                              'updated'   => _n( '%s product updated.', '%s products updated.', $bulk_counts['updated'], 'woocommerce' ),
                              /* translators: %s: product count */
                              'locked'    => _n( '%s product not updated, somebody is editing it.', '%s products not updated, somebody is editing them.', $bulk_counts['locked'], 'woocommerce' ),
                  Severity: Major
                  Found in includes/admin/class-wc-admin-post-types.php and 2 other locations - About 2 hrs to fix
                  includes/admin/class-wc-admin-post-types.php on lines 209..220
                  includes/admin/class-wc-admin-post-types.php on lines 222..233

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

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

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

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

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

                  Refactorings

                  Further Reading

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

                          $bulk_messages['shop_coupon'] = array(
                              /* translators: %s: coupon count */
                              'updated'   => _n( '%s coupon updated.', '%s coupons updated.', $bulk_counts['updated'], 'woocommerce' ),
                              /* translators: %s: coupon count */
                              'locked'    => _n( '%s coupon not updated, somebody is editing it.', '%s coupons not updated, somebody is editing them.', $bulk_counts['locked'], 'woocommerce' ),
                  Severity: Major
                  Found in includes/admin/class-wc-admin-post-types.php and 2 other locations - About 2 hrs to fix
                  includes/admin/class-wc-admin-post-types.php on lines 196..207
                  includes/admin/class-wc-admin-post-types.php on lines 209..220

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

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

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

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

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

                  Refactorings

                  Further Reading

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

                          $bulk_messages['shop_order'] = array(
                              /* translators: %s: order count */
                              'updated'   => _n( '%s order updated.', '%s orders updated.', $bulk_counts['updated'], 'woocommerce' ),
                              /* translators: %s: order count */
                              'locked'    => _n( '%s order not updated, somebody is editing it.', '%s orders not updated, somebody is editing them.', $bulk_counts['locked'], 'woocommerce' ),
                  Severity: Major
                  Found in includes/admin/class-wc-admin-post-types.php and 2 other locations - About 2 hrs to fix
                  includes/admin/class-wc-admin-post-types.php on lines 196..207
                  includes/admin/class-wc-admin-post-types.php on lines 222..233

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

                  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