CartoDB/cartodb20

View on GitHub
services/importer/lib/importer/downloader.rb

Summary

Maintainability
C
1 day
Test Coverage

File downloader.rb has 320 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'fileutils'
require 'open3'
require 'uri'
require_relative './exceptions'
require_relative './source_file'
Severity: Minor
Found in services/importer/lib/importer/downloader.rb - About 3 hrs to fix

    Class Downloader has 27 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Downloader
          include CartoDB::Importer2::QuotaCheckHelpers, Carto::UrlValidator, Carto::FilenameGenerator
    
          def self.supported_extensions
            @supported_extensions ||= CartoDB::Importer2::Unp::SUPPORTED_FORMATS
    Severity: Minor
    Found in services/importer/lib/importer/downloader.rb - About 3 hrs to fix

      Method bound_request has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def bound_request(file)
              request = http_client.request(@translated_url, typhoeus_options)
      
              request.on_headers do |response|
                @http_response_code = response.code
      Severity: Minor
      Found in services/importer/lib/importer/downloader.rb - 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 raise_error_for_response has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def raise_error_for_response(response)
              if response.timed_out?
                raise DownloadTimeoutError.new("TIMEOUT ERROR: Body:#{response.body}")
              elsif response.headers['Error'] && response.headers['Error'] =~ /too many nodes/
                raise TooManyNodesError.new(response.headers['Error'])
      Severity: Minor
      Found in services/importer/lib/importer/downloader.rb - About 45 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

      Method translate_url has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def translate_url(url)
              translator = supported_translator(url)
      
              raw_url = if translator
                          if translator.respond_to?(:rename_destination)
      Severity: Minor
      Found in services/importer/lib/importer/downloader.rb - About 35 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

      Method filename_from_headers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def filename_from_headers
              return nil unless headers
      
              disposition = headers['Content-Disposition']
              return false unless disposition
      Severity: Minor
      Found in services/importer/lib/importer/downloader.rb - About 35 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

      Method last_modified has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def last_modified
              return @last_modified if @last_modified
              return nil unless headers
      
              header_last_modified = headers['Last-Modified']
      Severity: Minor
      Found in services/importer/lib/importer/downloader.rb - 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

      Method run has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def run(_available_quota_in_bytes = nil)
              if @translated_url.include?('://')
                raise_if_over_storage_quota(requested_quota: content_length || 0,
                                            available_quota: size_limit_in_bytes,
                                            user_id: @user.id)
      Severity: Minor
      Found in services/importer/lib/importer/downloader.rb - 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