CartoDB/cartodb20

View on GitHub
app/models/table.rb

Summary

Maintainability
F
1 wk
Test Coverage

File table.rb has 1189 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'forwardable'

require_relative './table/column_typecaster'
require_relative './table/privacy_manager'
require_relative './table/relator'
Severity: Major
Found in app/models/table.rb - About 3 days to fix

    Class Table has 120 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Table
      extend Forwardable
      include Carto::TableUtils
      include ::LoggerHelper
    
    
    Severity: Major
    Found in app/models/table.rb - About 2 days to fix

      Method update_row! has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
      Open

        def update_row!(row_id, raw_attributes)
          retries = 0
      
          rows_updated = 0
          owner.in_database do |user_database|
      Severity: Minor
      Found in app/models/table.rb - About 5 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 insert_row! has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
      Open

        def insert_row!(raw_attributes)
          primary_key = nil
          owner.in_database do |user_database|
            schema = user_database.schema(name, schema: owner.database_schema, reload: true).map{|c| c.first}
            raw_attributes.delete(:id) unless schema.include?(:id)
      Severity: Minor
      Found in app/models/table.rb - About 4 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 records has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

        def records(options = {})
          rows = []
          records_count = 0
          page, per_page = CartoDB::Pagination.get_page_and_per_page(options)
          order_by_column = options[:order_by] || 'cartodb_id'
      Severity: Minor
      Found in app/models/table.rb - About 3 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 schema has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        def schema(options = {})
          first_columns     = []
          middle_columns    = []
          last_columns      = []
          owner.in_database.schema(name, schema: owner.database_schema, reload: options.fetch(:reload, true)).each do |column|
      Severity: Minor
      Found in app/models/table.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 set_the_geom_column! has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        def set_the_geom_column!(type = nil)
          if type.nil?
            if self.schema(reload: true).flatten.include?(THE_GEOM)
              if self.schema.select{ |k| k[0] == THE_GEOM }.first[1] == 'geometry'
                row = owner.in_database["select GeometryType(#{THE_GEOM}) FROM #{qualified_table_name} where #{THE_GEOM} is not null limit 1"].first
      Severity: Minor
      Found in app/models/table.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 after_create has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

        def after_create
          grant_select_to_tiler_user
      
          @force_schema = nil
          self.new_table = true
      Severity: Minor
      Found in app/models/table.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 import_cleanup has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def import_cleanup
            # When tables are created using ogr2ogr they are added a ogc_fid or gid primary key
            # In that case:
            #  - If cartodb_id already exists, remove ogc_fid
            #  - If cartodb_id does not exist, treat this field as the auxiliary column
      Severity: Minor
      Found in app/models/table.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 records has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def records(options = {})
          rows = []
          records_count = 0
          page, per_page = CartoDB::Pagination.get_page_and_per_page(options)
          order_by_column = options[:order_by] || 'cartodb_id'
      Severity: Major
      Found in app/models/table.rb - About 2 hrs to fix

        Method update_name_changes has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          def update_name_changes
            if @name_changed_from.present? && @name_changed_from != name
              reload
        
              unless register_table_only
        Severity: Minor
        Found in app/models/table.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 import_cleanup has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def import_cleanup
              # When tables are created using ogr2ogr they are added a ogc_fid or gid primary key
              # In that case:
              #  - If cartodb_id already exists, remove ogc_fid
              #  - If cartodb_id does not exist, treat this field as the auxiliary column
        Severity: Minor
        Found in app/models/table.rb - About 1 hr to fix

          Method update_row! has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def update_row!(row_id, raw_attributes)
              retries = 0
          
              rows_updated = 0
              owner.in_database do |user_database|
          Severity: Minor
          Found in app/models/table.rb - About 1 hr to fix

            Method update_name_changes has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def update_name_changes
                if @name_changed_from.present? && @name_changed_from != name
                  reload
            
                  unless register_table_only
            Severity: Minor
            Found in app/models/table.rb - About 1 hr to fix

              Method insert_row! has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def insert_row!(raw_attributes)
                  primary_key = nil
                  owner.in_database do |user_database|
                    schema = user_database.schema(name, schema: owner.database_schema, reload: true).map{|c| c.first}
                    raw_attributes.delete(:id) unless schema.include?(:id)
              Severity: Minor
              Found in app/models/table.rb - About 1 hr to fix

                Method import_to_cartodb has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                  def import_to_cartodb(uniname = nil)
                    if migrate_existing_table.present? || uniname
                      data_import.data_type = DataImport::TYPE_EXTERNAL_TABLE if data_import.data_type.nil?
                      data_import.data_source = migrate_existing_table || uniname
                      data_import.save
                Severity: Minor
                Found in app/models/table.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 set_the_geom_column! has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def set_the_geom_column!(type = nil)
                    if type.nil?
                      if self.schema(reload: true).flatten.include?(THE_GEOM)
                        if self.schema.select{ |k| k[0] == THE_GEOM }.first[1] == 'geometry'
                          row = owner.in_database["select GeometryType(#{THE_GEOM}) FROM #{qualified_table_name} where #{THE_GEOM} is not null limit 1"].first
                Severity: Minor
                Found in app/models/table.rb - About 1 hr to fix

                  Method before_create has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def before_create
                      raise CartoDB::QuotaExceeded if owner.over_table_quota?
                  
                      # The Table model only migrates now, never imports
                      if migrate_existing_table.present?
                  Severity: Minor
                  Found in app/models/table.rb - About 1 hr to fix

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

                      def record(identifier)
                        row = nil
                        owner.in_database do |user_database|
                          select_sql = schema.map { |column|
                            name, type = column
                    Severity: Minor
                    Found in app/models/table.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 before_create has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def before_create
                        raise CartoDB::QuotaExceeded if owner.over_table_quota?
                    
                        # The Table model only migrates now, never imports
                        if migrate_existing_table.present?
                    Severity: Minor
                    Found in app/models/table.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 manage_tags has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def manage_tags
                        if @user_table[:tags].blank?
                          Carto::Tag.where(user_id: user_id, table_id: id).each(&:destroy)
                        else
                          tag_names = @user_table.tags.split(',')
                    Severity: Minor
                    Found in app/models/table.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 after_create has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def after_create
                        grant_select_to_tiler_user
                    
                        @force_schema = nil
                        self.new_table = true
                    Severity: Minor
                    Found in app/models/table.rb - About 1 hr to fix

                      Method schema has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def schema(options = {})
                          first_columns     = []
                          middle_columns    = []
                          last_columns      = []
                          owner.in_database.schema(name, schema: owner.database_schema, reload: options.fetch(:reload, true)).each do |column|
                      Severity: Minor
                      Found in app/models/table.rb - About 1 hr to fix

                        Method import_to_cartodb has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def import_to_cartodb(uniname = nil)
                            if migrate_existing_table.present? || uniname
                              data_import.data_type = DataImport::TYPE_EXTERNAL_TABLE if data_import.data_type.nil?
                              data_import.data_source = migrate_existing_table || uniname
                              data_import.save
                        Severity: Minor
                        Found in app/models/table.rb - About 1 hr to fix

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

                            def name=(value)
                              value = value.downcase if value
                              return if value == @user_table.name || value.blank?
                          
                              new_name = register_table_only ? value : get_valid_name(value)
                          Severity: Minor
                          Found in app/models/table.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 create_table_in_database! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def create_table_in_database!
                              self.name ||= get_valid_name(self.name)
                          
                              owner.in_database do |user_database|
                                if force_schema.blank?
                          Severity: Minor
                          Found in app/models/table.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 handle_creation_error has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def handle_creation_error(e)
                              log_info(message: 'table#create error', exception: e)
                              # Remove the table, except if it already exists
                              unless self.name.blank? || e.message =~ /relation .* already exists/
                                @data_import.log.append ("Import ERROR: Dropping table #{qualified_table_name}") if @data_import
                          Severity: Minor
                          Found in app/models/table.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

                          Avoid deeply nested control flow statements.
                          Open

                                        if (retries += 1) > MAX_UPDATE_ROW_RETRIES
                                          log_error(message: 'Max update_row! retries reached',
                                                                user_id: user_id,
                                                                qualified_table_name: qualified_table_name,
                                                                row_id: row_id,
                          Severity: Major
                          Found in app/models/table.rb - About 45 mins to fix

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

                              def self.get_by_id(table_id, viewer_user)
                                table = nil
                                return table unless viewer_user
                            
                                table_temp = Carto::UserTable.where(id: table_id).first.service
                            Severity: Minor
                            Found in app/models/table.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 get_all_by_names has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def self.get_all_by_names(names, viewer_user)
                                names.map { |t|
                                  user_id = viewer_user.id
                                  table_name, table_schema = Table.table_and_schema(t)
                                  unless table_schema.nil?
                            Severity: Minor
                            Found in app/models/table.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 get_all_user_tables_by_names has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def self.get_all_user_tables_by_names(names, viewer_user)
                                names.map { |t|
                                  user_id = viewer_user.id
                                  table_name, table_schema = Table.table_and_schema(t)
                                  unless table_schema.nil?
                            Severity: Minor
                            Found in app/models/table.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 add_column! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def add_column!(options)
                                raise CartoDB::InvalidColumnName if CartoDB::Importer2::Column.rejected?(options[:name])
                                type = options[:type].convert_to_db_type
                                cartodb_type = options[:type].convert_to_cartodb_type
                                # FIXME: consider CartoDB::Importer2::Column.get_valid_column_name with CURRENT_COLUMN_SANITIZATION_VERSION
                            Severity: Minor
                            Found in app/models/table.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 cartodbfy has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def cartodbfy
                                start = Time.now
                                schema_name = owner.database_schema
                                table_name = "#{owner.database_schema}.#{self.name}"
                            
                            
                            Severity: Minor
                            Found in app/models/table.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 rename_column has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def rename_column(old_name, new_name='')
                                raise 'Please provide a column name' if new_name.empty?
                                raise 'This column cannot be renamed' if CARTODB_COLUMNS.include?(old_name.to_s)
                            
                                if CartoDB::Importer2::Column.reserved_or_unsupported?(new_name) || CARTODB_COLUMNS.include?(new_name)
                            Severity: Minor
                            Found in app/models/table.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 update_the_geom! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def update_the_geom!(attributes, primary_key)
                                return unless attributes[THE_GEOM].present? && attributes[THE_GEOM] != 'GeoJSON'
                                geojson = attributes[THE_GEOM]
                            
                                begin
                            Severity: Minor
                            Found in app/models/table.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 the_geom_type= has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def the_geom_type=(value)
                                self.the_geom_type_value = case value.downcase
                                  when 'geometry'
                                    'geometry'
                                  when 'point'
                            Severity: Minor
                            Found in app/models/table.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 add_table_to_stats
                                CartoDB::Stats::UserTables.instance.update_tables_counter(1)
                                CartoDB::Stats::UserTables.instance.update_tables_counter_per_user(1, self.owner.username)
                                CartoDB::Stats::UserTables.instance.update_tables_counter_per_host(1)
                                CartoDB::Stats::UserTables.instance.update_tables_counter_per_plan(1, self.owner.account_type)
                            Severity: Minor
                            Found in app/models/table.rb and 1 other location - About 30 mins to fix
                            app/models/table.rb on lines 1493..1497

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

                            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 remove_table_from_stats
                                CartoDB::Stats::UserTables.instance.update_tables_counter(-1)
                                CartoDB::Stats::UserTables.instance.update_tables_counter_per_user(-1, self.owner.username)
                                CartoDB::Stats::UserTables.instance.update_tables_counter_per_host(-1)
                                CartoDB::Stats::UserTables.instance.update_tables_counter_per_plan(-1, self.owner.account_type)
                            Severity: Minor
                            Found in app/models/table.rb and 1 other location - About 30 mins to fix
                            app/models/table.rb on lines 1486..1490

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

                            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