woocommerce/woocommerce

View on GitHub
includes/class-wc-download-handler.php

Summary

Maintainability
D
2 days
Test Coverage

File class-wc-download-handler.php has 362 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Download handler
 *
 * Handle digital downloads.
Severity: Minor
Found in includes/class-wc-download-handler.php - About 4 hrs to fix

    Method download_product has 68 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function download_product() {
            $product_id = absint( $_GET['download_file'] ); // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.VIP.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
            $product    = wc_get_product( $product_id );
            $data_store = WC_Data_Store::load( 'customer-download' );
    
    
    Severity: Major
    Found in includes/class-wc-download-handler.php - About 2 hrs to fix

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

          public static function readfile_chunked( $file, $start = 0, $length = 0 ) {
              if ( ! defined( 'WC_CHUNK_SIZE' ) ) {
                  define( 'WC_CHUNK_SIZE', 1024 * 1024 );
              }
              $handle = @fopen( $file, 'r' ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen
      Severity: Minor
      Found in includes/class-wc-download-handler.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 get_download_range has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected static function get_download_range( $file_size ) {
              $start          = 0;
              $download_range = array(
                  'start'            => $start,
                  'is_range_valid'   => false,
      Severity: Minor
      Found in includes/class-wc-download-handler.php - About 1 hr to fix

        Method readfile_chunked has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function readfile_chunked( $file, $start = 0, $length = 0 ) {
                if ( ! defined( 'WC_CHUNK_SIZE' ) ) {
                    define( 'WC_CHUNK_SIZE', 1024 * 1024 );
                }
                $handle = @fopen( $file, 'r' ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen
        Severity: Minor
        Found in includes/class-wc-download-handler.php - About 1 hr to fix

          Function download_product has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function download_product() {
                  $product_id = absint( $_GET['download_file'] ); // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.VIP.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
                  $product    = wc_get_product( $product_id );
                  $data_store = WC_Data_Store::load( 'customer-download' );
          
          
          Severity: Minor
          Found in includes/class-wc-download-handler.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 parse_file_path has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function parse_file_path( $file_path ) {
                  $wp_uploads     = wp_upload_dir();
                  $wp_uploads_dir = $wp_uploads['basedir'];
                  $wp_uploads_url = $wp_uploads['baseurl'];
          
          
          Severity: Minor
          Found in includes/class-wc-download-handler.php - About 1 hr to fix

            Function get_download_range has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                protected static function get_download_range( $file_size ) {
                    $start          = 0;
                    $download_range = array(
                        'start'            => $start,
                        'is_range_valid'   => false,
            Severity: Minor
            Found in includes/class-wc-download-handler.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 download_headers has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private static function download_headers( $file_path, $filename, $download_range = array() ) {
                    self::check_server_config();
                    self::clean_buffers();
                    wc_nocache_headers();
            
            
            Severity: Minor
            Found in includes/class-wc-download-handler.php - About 1 hr to fix

              Function check_download_login_required has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function check_download_login_required( $download ) {
                      if ( $download->get_user_id() && 'yes' === get_option( 'woocommerce_downloads_require_login' ) ) {
                          if ( ! is_user_logged_in() ) {
                              if ( wc_get_page_id( 'myaccount' ) ) {
                                  wp_safe_redirect( add_query_arg( 'wc_error', rawurlencode( __( 'You must be logged in to download files.', 'woocommerce' ) ), wc_get_page_permalink( 'myaccount' ) ) );
              Severity: Minor
              Found in includes/class-wc-download-handler.php - About 55 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 download_file_xsendfile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function download_file_xsendfile( $file_path, $filename ) {
                      $parsed_file_path = self::parse_file_path( $file_path );
              
                      /**
                       * Fallback on force download method for remote files. This is because:
              Severity: Minor
              Found in includes/class-wc-download-handler.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 download_headers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function download_headers( $file_path, $filename, $download_range = array() ) {
                      self::check_server_config();
                      self::clean_buffers();
                      wc_nocache_headers();
              
              
              Severity: Minor
              Found in includes/class-wc-download-handler.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 parse_file_path has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function parse_file_path( $file_path ) {
                      $wp_uploads     = wp_upload_dir();
                      $wp_uploads_dir = $wp_uploads['basedir'];
                      $wp_uploads_url = $wp_uploads['baseurl'];
              
              
              Severity: Minor
              Found in includes/class-wc-download-handler.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

              There are no issues that match your filters.

              Category
              Status