CartoDB/cartodb20

View on GitHub
app/models/visualization/collection.rb

Summary

Maintainability
D
2 days
Test Coverage

File collection.rb has 382 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'set'
require_relative './member'
require_relative './overlays'
require_relative '../../../services/data-repository/structures/collection'

Severity: Minor
Found in app/models/visualization/collection.rb - About 5 hrs to fix

    Class Collection has 38 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Collection
          # 'unauthenticated' overrides other filters
          # 'user_id' filtered by default if present upon fetch()
          # 'locked' is filtered but before the rest
          # 'exclude_shared' and
    Severity: Minor
    Found in app/models/visualization/collection.rb - About 5 hrs to fix

      Method compute_sharing_filter_dataset has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

            def compute_sharing_filter_dataset(filters)
              shared_filter = filters.delete(:shared)
              case shared_filter
                when FILTER_SHARED_YES
                  filters[:only_shared] = false
      Severity: Minor
      Found in app/models/visualization/collection.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 compute_liked_filter_dataset has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

            def compute_liked_filter_dataset(dataset, filters)
              only_liked = filters.delete(:only_liked)
              if [true, 'true'].include?(only_liked)
                if @user_id.nil?
                  nil
      Severity: Minor
      Found in app/models/visualization/collection.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 compute_sharing_filter_dataset has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def compute_sharing_filter_dataset(filters)
              shared_filter = filters.delete(:shared)
              case shared_filter
                when FILTER_SHARED_YES
                  filters[:only_shared] = false
      Severity: Minor
      Found in app/models/visualization/collection.rb - About 1 hr to fix

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

              def organization_shared_entities_count(type)
                type ||= @type
                user = ::User.where(id: @user_id).first
                if user.nil? || user.organization.nil?
                  0
        Severity: Minor
        Found in app/models/visualization/collection.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 filter_by_only_shared has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def filter_by_only_shared(dataset, filters)
                return dataset \
                  unless (filters[:user_id].present? && filters[:only_shared].present? && filters[:only_shared].to_s == 'true')
        
                shared_vis = user_shared_vis(filters[:user_id])
        Severity: Minor
        Found in app/models/visualization/collection.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 include_shared_entities has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def include_shared_entities(dataset, filters)
                return dataset unless filters[:user_id].present?
                return dataset if filters[:exclude_shared].present? && filters[:exclude_shared].to_s == 'true'
        
                shared_vis = user_shared_vis(filters[:user_id])
        Severity: Minor
        Found in app/models/visualization/collection.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

              def lazy_order_by_row_count(objects)
                viz_and_rows = objects.map { |obj| [obj, (obj.table ? obj.table.row_count_and_size.fetch(:row_count, 0) : 0)] }
                viz_and_rows.sort! { |vr_a, vr_b| vr_b[1] <=> vr_a[1] }
                viz_and_rows.map { |vr| vr[0] }
        Severity: Minor
        Found in app/models/visualization/collection.rb and 1 other location - About 40 mins to fix
        app/models/visualization/collection.rb on lines 355..358

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

        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 lazy_order_by_size(objects)
                viz_and_size = objects.map { |obj| [obj, (obj.table ? obj.table.row_count_and_size.fetch(:size, 0) : 0)] }
                viz_and_size.sort! { |vs_a, vs_b| vs_b[1] <=> vs_a[1] }
                viz_and_size.map { |vs| vs[0] }
        Severity: Minor
        Found in app/models/visualization/collection.rb and 1 other location - About 40 mins to fix
        app/models/visualization/collection.rb on lines 349..352

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

        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

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

              DataRepository::Collection::INTERFACE.each do |method_name|
                define_method(method_name) do |*arguments, &block|
                  result = collection.send(method_name, *arguments, &block)
                  return self if result.is_a?(DataRepository::Collection)
                  result
        Severity: Minor
        Found in app/models/visualization/collection.rb and 1 other location - About 20 mins to fix
        app/models/synchronization/collection.rb on lines 22..26

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

        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

        There are no issues that match your filters.

        Category
        Status