alexreisner/geocoder

View on GitHub

Showing 75 of 75 total issues

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

      def select_clause(columns, distance = nil, bearing = nil, distance_column = 'distance', bearing_column = 'bearing')
Severity: Minor
Found in lib/geocoder/stores/active_record.rb - About 35 mins to fix

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

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

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

          def approx_distance(latitude, longitude, lat_attr, lon_attr, options = {})
      Severity: Minor
      Found in lib/geocoder/sql.rb - About 35 mins 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)
              if doc["response"] == "INVALID ACCOUNT"
        Severity: Minor
        Found in lib/geocoder/lookups/ip2location.rb and 1 other location - About 35 mins to fix
        lib/geocoder/lookups/ipapi_com.rb on lines 36..46

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

        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/ipapi_com.rb and 1 other location - About 35 mins to fix
        lib/geocoder/lookups/ip2location.rb on lines 29..37

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

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

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

            def geocode
              do_lookup(false) do |o,rs|
                if r = rs.first
                  unless r.latitude.nil? or r.longitude.nil?
                    o.__send__  "#{self.class.geocoder_options[:latitude]}=",  r.latitude
        Severity: Minor
        Found in lib/geocoder/stores/active_record.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 results has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

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

            def geocoder_reject_non_ipv4_addresses(ip_addresses)
              ips = []
              for ip in ip_addresses
                begin
                  valid_ip = IPAddr.new(ip)
        Severity: Minor
        Found in lib/geocoder/request.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 results has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def results(query)
              return [] unless doc = fetch_data(query)
              if doc['error'].nil?
                [doc]
              # The API returned a 404 response, which indicates no results found
        Severity: Minor
        Found in lib/geocoder/lookups/latlon.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

        Avoid too many return statements within this method.
        Open

              return []
        Severity: Major
        Found in lib/geocoder/lookups/amap.rb - About 30 mins to fix

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

              def insert_into_table(table, filepath)
                start_time = Time.now
                print "Loading data for table #{table}"
                rows = []
                columns = table_columns(table)
          Severity: Minor
          Found in lib/maxmind_database.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 geocode has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def geocode
                do_lookup(false) do |o,rs|
                  if r = rs.first
                    unless r.coordinates.nil?
                      o.__send__ "#{self.class.geocoder_options[:coordinates]}=", r.coordinates.reverse
          Severity: Minor
          Found in lib/geocoder/stores/mongo_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 query_url_here_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def query_url_here_options(query, reverse_geocode)
                options = {
                  gen: 9,
                  apikey: configuration.api_key,
                  language: (query.language || configuration.language)
          Severity: Minor
          Found in lib/geocoder/lookups/here.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 reverse_geocode has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def reverse_geocode
                do_lookup(true) do |o,rs|
                  if r = rs.first
                    unless r.address.nil?
                      o.__send__ "#{self.class.geocoder_options[:fetched_address]}=", r.address
          Severity: Minor
          Found in lib/geocoder/stores/mongo_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 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 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

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

              def expire(url)
                if url == :all
                  if store.respond_to?(:keys)
                    urls.each{ |u| expire(u) }
                  else
          Severity: Minor
          Found in lib/geocoder/cache.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

          Severity
          Category
          Status
          Source
          Language