CartoDB/cartodb20

View on GitHub
app/models/user.rb

Summary

Maintainability
F
1 wk
Test Coverage

Class User has 148 methods (exceeds 20 allowed). Consider refactoring.
Open

class User < Sequel::Model
  include CartoDB::MiniSequel
  include CartoDB::UserDecorator
  include CartodbCentralSynchronizable
  include CartoDB::ConfigUtils
Severity: Major
Found in app/models/user.rb - About 2 days to fix

    File user.rb has 1094 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'cartodb/per_request_sequel_cache'
    require 'cartodb-common'
    require 'email_address'
    require 'securerandom'
    require_relative './user/user_decorator'
    Severity: Major
    Found in app/models/user.rb - About 2 days to fix

      Method before_save has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
      Open

        def before_save
          super
          self.quota_in_bytes = self.quota_in_bytes.to_i if !self.quota_in_bytes.nil? && self.quota_in_bytes != self.quota_in_bytes.to_i
          self.updated_at = Time.now
          # Set account_type and default values for organization users
      Severity: Minor
      Found in app/models/user.rb - About 1 day 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_destroy has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

        def before_destroy(skip_table_drop: false)
          ensure_nonviewer
      
          @org_id_for_org_wipe = nil
          error_happened = false
      Severity: Minor
      Found in app/models/user.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_save has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

        def after_save
          super
          save_metadata
          changes = (self.previous_changes.present? ? self.previous_changes.keys : [])
          db_service.set_statement_timeouts if changes.include?(:user_timeout) || changes.include?(:database_timeout)
      Severity: Minor
      Found in app/models/user.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 before_destroy has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def before_destroy(skip_table_drop: false)
          ensure_nonviewer
      
          @org_id_for_org_wipe = nil
          error_happened = false
      Severity: Major
      Found in app/models/user.rb - About 2 hrs to fix

        Consider simplifying this complex logical expression.
        Open

            if changes.include?(:account_type) || changes.include?(:available_for_hire) || changes.include?(:disqus_shortname) || changes.include?(:email) || \
               changes.include?(:website) || changes.include?(:name) || changes.include?(:description) || \
               changes.include?(:twitter_username) || changes.include?(:location)
              invalidate_varnish_cache(regex: '.*:vizjson')
            end
        Severity: Critical
        Found in app/models/user.rb - About 1 hr to fix

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

            def before_save
              super
              self.quota_in_bytes = self.quota_in_bytes.to_i if !self.quota_in_bytes.nil? && self.quota_in_bytes != self.quota_in_bytes.to_i
              self.updated_at = Time.now
              # Set account_type and default values for organization users
          Severity: Minor
          Found in app/models/user.rb - About 1 hr to fix

            Method set_viewer_quotas has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              def set_viewer_quotas
                self.quota_in_bytes = 0 unless quota_in_bytes == 0
                self.geocoding_quota = 0 unless geocoding_quota == 0
                self.soft_geocoding_limit = false if soft_geocoding_limit
                self.twitter_datasource_quota = 0 unless twitter_datasource_quota == 0
            Severity: Minor
            Found in app/models/user.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 db_size_in_bytes has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def db_size_in_bytes
                return 0 if self.new?
            
                attempts = 0
                begin
            Severity: Minor
            Found in app/models/user.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 save_metadata has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def save_metadata
                $users_metadata.HMSET key,
                                      'id',                        id,
                                      'database_name',             database_name,
                                      'database_password',         database_password,
            Severity: Minor
            Found in app/models/user.rb - About 1 hr to fix

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

                def organization_validation
                  if new?
                    organization.validate_for_signup(errors, self)
              
                    unless valid_email_domain?(email)
              Severity: Minor
              Found in app/models/user.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

                          self.mobile_gis_extension = true unless changed_columns.include?(:mobile_gis_extension)
              Severity: Major
              Found in app/models/user.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            self.mobile_custom_watermark = false unless changed_columns.include?(:mobile_custom_watermark)
                Severity: Major
                Found in app/models/user.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              self.mobile_xamarin = true unless changed_columns.include?(:mobile_xamarin)
                  Severity: Major
                  Found in app/models/user.rb - About 45 mins to fix

                    Method in_database has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def in_database(options = {}, &block)
                        if options[:statement_timeout]
                          in_database.run("SET statement_timeout TO #{options[:statement_timeout]}")
                        end
                    
                    
                    Severity: Minor
                    Found in app/models/user.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

                    Avoid deeply nested control flow statements.
                    Open

                                self.mobile_offline_maps = false unless changed_columns.include?(:mobile_offline_maps)
                    Severity: Major
                    Found in app/models/user.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                  self.mobile_max_open_users = 10000 unless changed_columns.include?(:mobile_max_open_users)
                      Severity: Major
                      Found in app/models/user.rb - About 45 mins to fix

                        Method validate_password has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def validate_password
                            validates_presence :password if new? && crypted_password.blank?
                        
                            if new? || (password.present? && !@new_password.present?)
                              errors.add(:password, "is not confirmed") unless password == password_confirmation
                        Severity: Minor
                        Found in app/models/user.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

                        Avoid deeply nested control flow statements.
                        Open

                                    self.mobile_max_private_users = 10 unless changed_columns.include?(:mobile_max_private_users)
                        Severity: Major
                        Found in app/models/user.rb - About 45 mins to fix

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

                            def visualization_count(filters = {})
                              return 0 unless id
                          
                              vqb = Carto::VisualizationQueryBuilder.new
                              vqb.with_type(filters[:type]) if filters[:type]
                          Severity: Minor
                          Found in app/models/user.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 change_password has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def change_password(old_password, new_password_value, new_password_confirmation_value)
                              # First of all reset fields
                              @old_password_validated = nil
                              @new_password_confirmation = nil
                              # Mark as changing passwords
                          Severity: Minor
                          Found in app/models/user.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 before_validation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def before_validation
                              self.email = clean_email(email.to_s)
                              self.geocoding_quota ||= DEFAULT_GEOCODING_QUOTA
                              self.here_isolines_quota ||= DEFAULT_HERE_ISOLINES_QUOTA
                              self.mapzen_routing_quota ||= DEFAULT_MAPZEN_ROUTING_QUOTA
                          Severity: Minor
                          Found in app/models/user.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 importing_jobs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def importing_jobs
                              imports = DataImport.where(state: ['complete', 'failure']).invert
                                .where(user_id: self.id)
                                .where { created_at > Time.now - 24.hours }.all
                              running_import_ids = Resque::Worker.all.map { |worker| worker.job["payload"]["args"].first["job_id"] rescue nil }.compact
                          Severity: Minor
                          Found in app/models/user.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