geokit/geokit

View on GitHub

Showing 18 of 18 total issues

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

      def self.set_address_components(result_json, loc)
        if result_json['context']
          result_json['context'].each do |context|
            if context['id'] =~ /^country\./
              loc.country = context['text']
Severity: Minor
Found in lib/geokit/geocoders/mapbox.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 set_address_components has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def self.set_address_components(loc, addr)
        addr['address_components'].each do |comp|
          types = comp['types']
          case
          when types.include?('subpremise')
Severity: Minor
Found in lib/geokit/geocoders/google.rb - About 1 hr to fix

    Method set_address_components has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.set_address_components(address_data, loc)
            return unless address_data
            loc.country        = address_data['country']
            loc.country_code   = address_data['country_code'].upcase if address_data['country_code']
            loc.state_name     = address_data['state']
    Severity: Minor
    Found in lib/geokit/geocoders/opencage.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 submit_url has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.submit_url(query_string, options = {})
            language_str = options[:language] ? "&language=#{options[:language]}" : ''
            query_string = "/maps/api/geocode/json?sensor=false&#{query_string}#{language_str}"
            if client_id && cryptographic_key
              channel_string = channel ? "&channel=#{channel}" : ''
    Severity: Minor
    Found in lib/geokit/geocoders/google.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 parse_json has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.parse_json(results)
            return GeoLoc.new if results.empty?
            if results.is_a?(Hash)
              return GeoLoc.new unless results['status']['message'] == 'OK'
            end
    Severity: Minor
    Found in lib/geokit/geocoders/opencage.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 set_address_components has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.set_address_components(address_data, loc)
            return unless address_data
            loc.country = address_data['country']
            loc.country_code = address_data['country_code'].upcase if address_data['country_code']
            loc.state_name = address_data['state']
    Severity: Minor
    Found in lib/geokit/geocoders/openstreetmap.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 set_address_components has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.set_address_components(loc, addr)
            addr['address_components'].each do |comp|
              types = comp['types']
              case
              when types.include?('subpremise')
    Severity: Minor
    Found in lib/geokit/geocoders/google.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 contains? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def contains?(point)
          last_point = @points[-1]
          oddNodes = false
          x = point.lng
          y = point.lat
    Severity: Minor
    Found in lib/geokit/polygon.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 parse_json has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.parse_json(results)
            if results.is_a?(Hash)
              return GeoLoc.new if results['error']
              results = [results]
            end
    Severity: Minor
    Found in lib/geokit/geocoders/openstreetmap.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 self.parse_json(results)
            boss_results = results && results['bossresponse'] && results['bossresponse']['placefinder'] && results['bossresponse']['placefinder']['results']
            return GeoLoc.new unless boss_results && boss_results.first
            loc = nil
            boss_results.each do |result|
    Severity: Minor
    Found in lib/geokit/geocoders/yahoo.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 normalize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.normalize(thing, other = nil)
          return Geokit::LatLng.new(thing, other) if other
    
          case thing
          when String
    Severity: Minor
    Found in lib/geokit/lat_lng.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 submit_url has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.submit_url(address)
            if key.nil? || key.empty?
              raise(Geokit::Geocoders::GeocodeError, 'Geonames requires a key to use their service.')
            end
    
    
    Severity: Minor
    Found in lib/geokit/geocoders/geonames.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 parse_json has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.parse_json(results)
            return GeoLoc.new unless results['info']['statuscode'] == 0
            loc = nil
            results['results'].each do |result|
              result['locations'].each do |location|
    Severity: Minor
    Found in lib/geokit/geocoders/mapquest.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 do_geocode has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.do_geocode(address, options = {})
            bias_str = options[:bias] ? construct_bias_string_from_options(options[:bias]) : ''
            components_str = options[:components] ? construct_components_string_from_options(options[:components]) : ''
            address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address
            url = submit_url("address=#{Geokit::Inflector.url_escape(address_str)}#{bias_str}#{components_str}", options)
    Severity: Minor
    Found in lib/geokit/geocoders/google.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 sign has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def sign(parsed_url)
        @params = {
          'oauth_consumer_key' => @consumer_key,
          'oauth_nonce' => nonce,
          'oauth_signature_method' => @sig_method,
    Severity: Minor
    Found in lib/geokit/geocoders/yahoo.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 set_address_components has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.set_address_components(loc, l, country, locality)
            loc.country_code = country['CountryNameCode']
            loc.full_address = country['AddressLine']
            loc.street_address = l['name']
            loc.street_number = locality['Thoroughfare']['Premise']['PremiseNumber'] rescue nil
    Severity: Minor
    Found in lib/geokit/geocoders/yandex.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

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

        class_eval <<-EOS, __FILE__, __LINE__
          def self.#{sym}
            if defined?(#{sym.to_s.upcase})
              #{sym.to_s.upcase}
            else
    Severity: Minor
    Found in lib/geokit.rb and 1 other location - About 15 mins to fix
    lib/geokit/geocoders.rb on lines 51..67

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

    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_eval <<-EOS, __FILE__, __LINE__
              def self.#{sym}
                value = if defined?(#{sym.to_s.upcase})
                  #{sym.to_s.upcase}
                else
    Severity: Minor
    Found in lib/geokit/geocoders.rb and 1 other location - About 15 mins to fix
    lib/geokit.rb on lines 7..19

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

    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

    Severity
    Category
    Status
    Source
    Language