alexreisner/geocoder

View on GitHub

Showing 88 of 88 total issues

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

            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

              Similar blocks of code found in 3 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_io.rb and 2 other locations - About 35 mins to fix
              lib/geocoder/lookups/ip2location.rb on lines 33..41
              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 3 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 2 other locations - About 35 mins to fix
              lib/geocoder/lookups/ip2location.rb on lines 33..41
              lib/geocoder/lookups/ip2location_io.rb on lines 32..40

              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 3 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 2 other locations - About 35 mins to fix
              lib/geocoder/lookups/ip2location_io.rb on lines 32..40
              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

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

                  def results(query)
                    return [] unless doc = fetch_data(query)
                    if doc['meta'] && doc['meta']['error']
                      Geocoder.log(:warn, "2gis Geocoding API error: #{doc['meta']["code"]} (#{doc['meta']['error']["message"]}).")
                      return []
              Severity: Minor
              Found in lib/geocoder/lookups/twogis.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 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 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

              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 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))
                    return [] unless doc['type'] == 'FeatureCollection'
                    return [] unless doc['features'] || doc['features'].present?
              
              
              Severity: Minor
              Found in lib/geocoder/lookups/photon.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
                Severity
                Category
                Status
                Source
                Language