CartoDB/cartodb20

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

Summary

Maintainability
F
4 days
Test Coverage

Class Visualization has 136 methods (exceeds 20 allowed). Consider refactoring.
Open

class Carto::Visualization < ActiveRecord::Base
  include CacheHelper
  include Carto::UUIDHelper
  include Carto::AuthTokenGenerator
  include Carto::VisualizationDependencies
Severity: Major
Found in app/models/carto/visualization.rb - About 2 days to fix

    File visualization.rb has 698 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'active_record'
    require 'cartodb-common'
    require_relative '../visualization/stats'
    require_relative '../quota_checker'
    require_dependency 'carto/named_maps/api'
    Severity: Major
    Found in app/models/carto/visualization.rb - About 1 day to fix

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

        def propagate_name
          # TODO: Move this to ::Table?
          return if table.changing_name?
          table.register_table_only = register_table_only
          table.name = name
      Severity: Minor
      Found in app/models/carto/visualization.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 validate_change_to_private has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def validate_change_to_private
          if (!user&.private_tables_enabled? && table?) || (!user&.private_maps_enabled? && map?)
            errors.add(:privacy, 'cannot be set to private')
          end
      
      
      Severity: Minor
      Found in app/models/carto/visualization.rb - About 55 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 children has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def children
          ordered = []
          children_vis = self.unordered_children
          if children_vis.count > 0
            ordered << children_vis.select { |vis| vis.prev_id.nil? }.first
      Severity: Minor
      Found in app/models/carto/visualization.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 validate_change_to_public has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def validate_change_to_public
          return unless !privacy_was || privacy_was == Carto::Visualization::PRIVACY_PRIVATE
      
          if map? && CartoDB::QuotaChecker.new(user).will_be_over_public_map_quota?
            errors.add(:privacy, 'over account public map quota')
      Severity: Minor
      Found in app/models/carto/visualization.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 validate_privacy_changes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def validate_privacy_changes
          return unless privacy_changed? && (map? || table?)
      
          is_privacy_private? ? validate_change_to_private : validate_change_to_public
        end
      Severity: Minor
      Found in app/models/carto/visualization.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

      There are no issues that match your filters.

      Category
      Status