Showing 32 of 32 total issues

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

  def parse(geojson, opts={})
    return nil if geojson.nil? || geojson.try(:empty?)
    geojson_hash = geojson.is_a?(Hash) ? geojson : JSON.parse(geojson)
    decoded_geojson = RGeo::GeoJSON.decode(geojson_hash)
    decoded_geojson = decoded_geojson.first if decoded_geojson.is_a? Enumerable
Severity: Minor
Found in lib/geo_json.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 factory.multi_point(points).as_text      if points.size > 0
Severity: Major
Found in lib/mootiro_importer.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

        return factory.multi_polygon(polygons).as_text  if polygons.size > 0
    Severity: Major
    Found in lib/mootiro_importer.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

          return factory.multi_line_string(lines).as_text if lines.size > 0
      Severity: Major
      Found in lib/mootiro_importer.rb - About 30 mins to fix

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

            def self.serialized_as(format, ids=nil)
              collection = (ids ? where(id: ids) : all).map { |obj| active_model_serializer.new(obj) }
              hashs_collection = collection.map &:serializable_hash
              case format
                when :json    then hashs_collection.to_json
        Severity: Minor
        Found in app/models/concerns/exportable.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 map_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def map_options(obj)
              obj_type = object_type obj
              geojsonTileURL = obj_type == :map ? "/maps/#{obj.id}/tile/{z}/{x}/{y}" : "/geo_data/tile/{z}/{x}/{y}"
              opts = {
                layers: obj.try(:layers_values),
        Severity: Minor
        Found in app/helpers/concerns/components_helper.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 save_object has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def save_object(obj, params_hash)
            obj.assign_attributes(params_hash)
            changes = obj.changes
            if obj.valid? && obj.save
              obj_name = obj.class.name.underscore
        Severity: Minor
        Found in app/controllers/concerns/utils.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 featured= has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def featured=(value)
              if value == true
                Featured.find_or_create_by(_featured_params)
              elsif value == false
                featured = Featured.where(_featured_params).first
        Severity: Minor
        Found in app/models/concerns/featurable.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 selector_option has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def selector_option(label, param, value, default=false, class_name=nil)
              class_name = value unless class_name
              selected = params[param] == value.to_s || (params[param].nil? && default)
              "<a href=\"?#{param}=#{value}\" class=\"option #{class_name}#{' selected' if selected}\" data-selector-param=\"#{param}\" data-selector-value=\"#{value}\" #{'data-selector-default="true"' if default}>#{label}</a>".html_safe
        
        
        Severity: Minor
        Found in app/helpers/concerns/components_helper.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 cleaned_relations_attributes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def cleaned_relations_attributes(_params)
            _attrs = JSON.parse _params[:relations_attributes]
            _attrs.map do |r|
              OpenStruct.new(
                id:        (r['id'].blank? ? nil : r['id'].to_i    ),
        Severity: Minor
        Found in app/controllers/concerns/utils.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

            when 'map'
              (current_user ? [:edit] : []) + [:star, :history, :flag] + (can_delete? ? [:delete] : []) +
                (is_admin? ? [:featured] : [])
        Severity: Minor
        Found in app/presenters/toolbar_presenter.rb and 1 other location - About 15 mins to fix
        app/presenters/toolbar_presenter.rb on lines 27..29

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

        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

            when 'geo_data'
              (current_user ? [:edit] : []) + [:star, :history, :flag] + (can_delete? ? [:delete] : []) +
                (is_admin? ? [:featured] : [])
        Severity: Minor
        Found in app/presenters/toolbar_presenter.rb and 1 other location - About 15 mins to fix
        app/presenters/toolbar_presenter.rb on lines 30..32

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

        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