alexreisner/geocoder

View on GitHub

Showing 75 of 75 total issues

Method included has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def self.included(base)
      base.extend ClassMethods
      base.class_eval do

        # scope: geocoded objects
Severity: Minor
Found in lib/geocoder/stores/active_record.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 to_WGS84 has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def to_WGS84(latlng)
      latitude = latlng[0]
      longitude = latlng[1]

      a = 6_377_563.396
Severity: Minor
Found in lib/easting_northing.rb - About 1 hr to fix

    Method street_services has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def street_services
          @street_services ||= [
            :location_iq,
            :dstk,
            :esri,
    Severity: Minor
    Found in lib/geocoder/lookup.rb - About 1 hr to fix

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

          def self.run(args, out = STDOUT)
            show_url  = false
            show_json = false
      
            # remove arguments that are probably coordinates so they are not
      Severity: Minor
      Found in lib/geocoder/cli.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 results has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def results(query)
            # don't look up a loopback or private address, just return the stored result
            return [] if query.internal_ip_address?
            doc = fetch_data(query)
            if doc and doc.is_a?(Hash)
      Severity: Minor
      Found in lib/geocoder/lookups/pointpin.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 results has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def results(query)
            return [] unless doc = fetch_data(query)
            if err = doc['error']
              if err["status"] == 401 and err["message"] == "invalid key"
                raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid API key.")
      Severity: Minor
      Found in lib/geocoder/lookups/yandex.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

      Consider simplifying this complex logical expression.
      Open

            if !options[:street_address] and (options[:ip_address] or ip_address?)
              name = options[:ip_lookup] || Configuration.ip_lookup || Geocoder::Lookup.ip_services.first
            else
              name = options[:lookup] || Configuration.lookup || Geocoder::Lookup.street_services.first
            end
      Severity: Major
      Found in lib/geocoder/query.rb - About 1 hr to fix

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

            def results(query)
              # don't look up a loopback or private address, just return the stored result
              return [reserved_result(query.text)] if query.internal_ip_address?
        
              return [] unless doc = fetch_data(query)
        Severity: Minor
        Found in lib/geocoder/lookups/ipstack.rb and 1 other location - About 55 mins to fix
        lib/geocoder/lookups/ipregistry.rb on lines 45..57

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

        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 2 locations. Consider refactoring.
        Open

            def results(query)
              # don't look up a loopback or private address, just return the stored result
              return [reserved_result(query.text)] if query.internal_ip_address?
        
              return [] unless (doc = fetch_data(query))
        Severity: Minor
        Found in lib/geocoder/lookups/ipregistry.rb and 1 other location - About 55 mins to fix
        lib/geocoder/lookups/ipstack.rb on lines 36..48

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

        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 2 locations. Consider refactoring.
        Open

        module Geocoder
          module Generators
            module Maxmind
              class GeoliteCountryGenerator < Rails::Generators::Base
                include Rails::Generators::Migration
        Severity: Minor
        Found in lib/generators/geocoder/maxmind/geolite_country_generator.rb and 1 other location - About 55 mins to fix
        lib/generators/geocoder/maxmind/geolite_city_generator.rb on lines 4..24

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

        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 2 locations. Consider refactoring.
        Open

        module Geocoder
          module Generators
            module Maxmind
              class GeoliteCityGenerator < Rails::Generators::Base
                include Rails::Generators::Migration
        Severity: Minor
        Found in lib/generators/geocoder/maxmind/geolite_city_generator.rb and 1 other location - About 55 mins to fix
        lib/generators/geocoder/maxmind/geolite_country_generator.rb on lines 4..24

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

        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 results has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def results(query)
              return [] unless doc = fetch_data(query)
              return [] unless doc['Response'] && doc['Response']['View']
              if r=doc['Response']['View']
                return [] if r.nil? || !r.is_a?(Array) || r.empty?
        Severity: Minor
        Found in lib/geocoder/lookups/here.rb - 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

        Method results has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def results(query)
              if configuration[:file]
                geoip_class = RUBY_PLATFORM == "java" ? JGeoIP : GeoIP
                result = geoip_class.new(configuration[:file]).city(query.to_s)
                result.nil? ? [] : [encode_hash(result.to_hash)]
        Severity: Minor
        Found in lib/geocoder/lookups/maxmind_local.rb - 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

        Method results has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def results(query)
              return [] unless doc = fetch_data(query)
        
              if (!query.reverse_geocode?)
                return [] if !doc['locations'] || doc['locations'].empty?
        Severity: Minor
        Found in lib/geocoder/lookups/esri.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 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 results has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def results(query)
              return [] unless doc = fetch_data(query)
              return doc["results"] if doc['error'].nil?
              
              if doc['error'] == 'Invalid API key'
        Severity: Minor
        Found in lib/geocoder/lookups/geocodio.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 within_bounding_box has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def within_bounding_box(sw_lat, sw_lng, ne_lat, ne_lng, lat_attr, lon_attr)
        Severity: Minor
        Found in lib/geocoder/sql.rb - About 45 mins to fix

          Method results has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def results(query, reverse = false)
                return [] unless doc = fetch_data(query)
                case doc['status']
                when 0
                  return [doc[content_key]] unless doc[content_key].blank?
          Severity: Minor
          Found in lib/geocoder/lookups/baidu.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 full_distance has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def full_distance(latitude, longitude, lat_attr, lon_attr, options = {})
          Severity: Minor
          Found in lib/geocoder/sql.rb - About 35 mins to fix

            Method full_bearing has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def full_bearing(latitude, longitude, lat_attr, lon_attr, options = {})
            Severity: Minor
            Found in lib/geocoder/sql.rb - About 35 mins to fix
              Severity
              Category
              Status
              Source
              Language