alexreisner/geocoder

View on GitHub

Showing 88 of 88 total issues

Method near_scope_options has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def near_scope_options(latitude, longitude, radius = 20, options = {})
        if options[:units]
          options[:units] = options[:units].to_sym
        end
        latitude_attribute = options[:latitude] || geocoder_options[:latitude]
Severity: Minor
Found in lib/geocoder/stores/active_record.rb - About 1 hr to fix

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

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

          def extract_coordinates(point)
            case point
            when Array
              if point.size == 2
                lat, lon = point
      Severity: Minor
      Found in lib/geocoder/calculations.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 included has 36 lines of code (exceeds 25 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

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

            def results(query)
              if configuration[:file]
                geoip_class = RUBY_PLATFORM == "java" ? JGeoIP : GeoIP
                geoip_instance = geoip_class.new(configuration[:file])
                result =
        Severity: Minor
        Found in lib/geocoder/lookups/maxmind_local.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 select_clause has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def select_clause(columns, distance = nil, bearing = nil, distance_column = 'distance', bearing_column = 'bearing')
                if columns == :id_only
                  return full_column_name(primary_key)
                elsif columns == :geo_only
                  clause = ""
        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 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 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 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 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def results(query)
                return [] unless doc = fetch_data(query)
                if [400, 403].include? doc['statusCode']
                  if doc['statusCode'] == 403 and doc['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

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

                  def results(query)
                    return [] unless (doc = fetch_data(query))
            
                    # The rest of the status codes should be already handled by the default
                    # functionality as the API returns correct HTTP response codes in most
            Severity: Minor
            Found in lib/geocoder/lookups/geoapify.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

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

            Severity
            Category
            Status
            Source
            Language