geokit/geokit-rails

View on GitHub

Showing 9 of 9 total issues

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

  module Adapters
    class PostgreSQL < Abstract
      
      def sphere_distance_sql(lat, lng, multiplier)
        %|
Severity: Major
Found in lib/geokit-rails/adapters/postgresql.rb and 1 other location - About 1 hr to fix
lib/geokit-rails/adapters/mysql.rb on lines 2..16

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

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 Adapters
    class MySQL < Abstract
      
      def sphere_distance_sql(lat, lng, multiplier)
        %|
Severity: Major
Found in lib/geokit-rails/adapters/mysql.rb and 1 other location - About 1 hr to fix
lib/geokit-rails/adapters/postgresql.rb on lines 2..16

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

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

        def acts_as_mappable(options = {})
          metaclass = (class << self; self; end)

          include Geokit::ActsAsMappable

Severity: Minor
Found in lib/geokit-rails/acts_as_mappable/glue.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 acts_as_mappable has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def acts_as_mappable(options = {})
          metaclass = (class << self; self; end)

          include Geokit::ActsAsMappable

Severity: Minor
Found in lib/geokit-rails/acts_as_mappable/glue.rb - About 1 hr to fix

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

          def formulate_bounds_from_distance(options, origin, units)
            distance = options[:within] if options.has_key?(:within) && options[:within].is_a?(Numeric)
            distance = options[:range].last-(options[:range].exclude_end?? 1 : 0) if options.has_key?(:range)
            if distance
              Geokit::Bounds.from_point_and_radius(origin,distance,:units=>units)
    Severity: Minor
    Found in lib/geokit-rails/acts_as_mappable/class_methods.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

    Consider simplifying this complex logical expression.
    Open

              if reflection = Geokit::ActsAsMappable.end_of_reflection_chain(self.through, self)
                metaclass.instance_eval do
                  OPTION_SYMBOLS.each do |method_name|
                    define_method method_name do
                      reflection.klass.send(method_name)
    Severity: Major
    Found in lib/geokit-rails/acts_as_mappable/glue.rb - About 40 mins to fix

      Method end_of_reflection_chain has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.end_of_reflection_chain(through, klass)
            while through
              reflection = nil
              if through.is_a?(Hash)
                association, through = through.to_a.first
      Severity: Minor
      Found in lib/geokit-rails/acts_as_mappable.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 bound_conditions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def bound_conditions(bounds, inclusive = false)
              return nil unless bounds
              if inclusive
                lt_operator = :lteq
                gt_operator = :gteq
      Severity: Minor
      Found in lib/geokit-rails/acts_as_mappable/class_methods.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 distance_conditions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def distance_conditions(options)
              origin  = extract_origin_from_options(options)
              units   = extract_units_from_options(options)
              formula = extract_formula_from_options(options)
              distance_column_name = distance_sql(origin, units, formula)
      Severity: Minor
      Found in lib/geokit-rails/acts_as_mappable/class_methods.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