alexreisner/geocoder

View on GitHub
lib/geocoder/lookups/base.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Base has 31 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Base
      def initialize
        @cache = nil
      end

Severity: Minor
Found in lib/geocoder/lookups/base.rb - About 3 hrs to fix

    Method fetch_raw_data has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

          def fetch_raw_data(query)
            key = cache_key(query)
            if cache and body = cache[key]
              @cache_hit = true
            else
    Severity: Minor
    Found in lib/geocoder/lookups/base.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 make_api_request has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def make_api_request(query)
            uri = URI.parse(query_url(query))
            Geocoder.log(:debug, "Geocoder: HTTP request being made for #{uri.to_s}")
            http_client.start(uri.host, uri.port, use_ssl: use_ssl?, open_timeout: configuration.timeout, read_timeout: configuration.timeout) do |client|
              configure_ssl!(client) if use_ssl?
    Severity: Minor
    Found in lib/geocoder/lookups/base.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 http_client has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def http_client
            proxy_name = "#{protocol}_proxy"
            if proxy = configuration.send(proxy_name)
              proxy_url = !!(proxy =~ /^#{protocol}/) ? proxy : protocol + '://' + proxy
              begin
    Severity: Minor
    Found in lib/geocoder/lookups/base.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 parse_json has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def parse_json(data)
            if defined?(ActiveSupport::JSON)
              ActiveSupport::JSON.decode(data)
            else
              JSON.parse(data)
    Severity: Minor
    Found in lib/geocoder/lookups/base.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 check_response_for_errors! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def check_response_for_errors!(response)
            if response.code.to_i == 400
              raise_error(Geocoder::InvalidRequest) ||
                Geocoder.log(:warn, "Geocoding API error: 400 Bad Request")
            elsif response.code.to_i == 401
    Severity: Minor
    Found in lib/geocoder/lookups/base.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 raise_error has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def raise_error(error, message = nil)
            exceptions = configuration.always_raise
            if exceptions == :all or exceptions.include?( error.is_a?(Class) ? error : error.class )
              raise error, message
            else
    Severity: Minor
    Found in lib/geocoder/lookups/base.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 hash_to_query has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def hash_to_query(hash)
            require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
            hash.collect{ |p|
              p[1].nil? ? nil : p.map{ |i| CGI.escape i.to_s } * '='
            }.compact.sort * '&'
    Severity: Minor
    Found in lib/geocoder/lookups/base.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