CartoDB/cartodb20

View on GitHub
app/controllers/carto/api/layer_presenter.rb

Summary

Maintainability
F
3 days
Test Coverage

File layer_presenter.rb has 653 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_dependency 'carto/api/infowindow_migrator'
require_dependency 'carto/table_utils'

module Carto
  module Api
Severity: Major
Found in app/controllers/carto/api/layer_presenter.rb - About 1 day to fix

    Class LayerPresenter has 29 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class LayerPresenter
          include InfowindowMigrator
          include Carto::TableUtils
    
          PUBLIC_VALUES = %W{ options kind infowindow tooltip id order }
    Severity: Minor
    Found in app/controllers/carto/api/layer_presenter.rb - About 3 hrs to fix

      Class StylePropertiesGenerator has 26 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class StylePropertiesGenerator
            def initialize(layer)
              @layer = layer
              @wizard_properties = @layer.options['wizard_properties']
              @source_type = @wizard_properties.present? ? @wizard_properties['type'] : nil
      Severity: Minor
      Found in app/controllers/carto/api/layer_presenter.rb - About 3 hrs to fix

        Method migrate has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

              def migrate(options)
                return nil unless @wizard_properties.present?
        
                wpp = @wizard_properties['properties']
        
        
        Severity: Minor
        Found in app/controllers/carto/api/layer_presenter.rb - About 2 hrs 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 migrate has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def migrate(options)
                return nil unless @wizard_properties.present?
        
                wpp = @wizard_properties['properties']
        
        
        Severity: Minor
        Found in app/controllers/carto/api/layer_presenter.rb - About 1 hr to fix

          Method as_torque has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def as_torque
                  api_templates_type = @options.fetch(:https_request, false) ? 'private' : 'public'
                  layer_options = decorate_with_data(
                      # Make torque always have a SQL query too (as vizjson v2)
                      @layer.options.merge({ 'query' => wrap(sql_from(@layer.options), @layer.options) }),
          Severity: Minor
          Found in app/controllers/carto/api/layer_presenter.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 qualify_table_name has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def qualify_table_name
                  layer_opts = @layer.options.nil? ? Hash.new : @layer.options
          
                  # if the table_name already have a schema don't add another one.
                  # This case happens when you share a layer already shared with you
          Severity: Minor
          Found in app/controllers/carto/api/layer_presenter.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 options_data_v2 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                def options_data_v2
                  if @options[:full]
                    decorate_with_data(@layer.options, @decoration_data)
                  else
                    sql = sql_from(@layer.options)
          Severity: Minor
          Found in app/controllers/carto/api/layer_presenter.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 generate_color has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                def generate_color(wpp)
                  color = {}
          
                  %w(polygon marker).each do |prefix|
                    set_if_present(color, 'fixed', wpp["#{prefix}-fill"])
          Severity: Minor
          Found in app/controllers/carto/api/layer_presenter.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 viewer_is_owner? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def viewer_is_owner?
                  return (@owner_user.id == @viewer_user.id) if (@owner_user && @viewer_user)
          
                  # This can be removed if 'user_name' support is dropped
                  layer_opts = @layer.options.nil? ? Hash.new : @layer.options
          Severity: Minor
          Found in app/controllers/carto/api/layer_presenter.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 wizard_properties_properties_to_style_properties_properties has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                def wizard_properties_properties_to_style_properties_properties(wizard_properties_properties, type)
                  spp = {}
                  wpp = wizard_properties_properties
                  return spp unless wpp
          
          
          Severity: Minor
          Found in app/controllers/carto/api/layer_presenter.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 layer_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                def layer_options
                  layer_opts = @layer.options.nil? ? Hash.new : @layer.options
                  if layer_opts['table_name'] && !viewer_is_owner?
                    layer_opts['table_name'] = qualify_table_name
                  end
          Severity: Minor
          Found in app/controllers/carto/api/layer_presenter.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