robertgauld/OSMExtender

View on GitHub

Showing 133 of 203 total issues

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

  def gdpr_consent_given
    if params[:gdpr_consent].eql?('1')
      if current_user.update gdpr_consent_at: Time.now.utc
        redirect_to session[:return_to].nil? ? my_page_path : session.delete(:return_to), :notice => 'Thank you, your consent has been recorded.'
      else
Severity: Minor
Found in app/controllers/users_controller.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 require_section_subscription has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def require_section_subscription(level, section=current_section)
    section = Osm::Section.get(api, section) unless section.is_a?(Osm::Section)
    return unless section.nil? || !section.subscription_at_least?(level)
    flash[:error] = "#{section.nil? ? 'Unknown section' : section.name} does not have the right subscription level for that (#{Osm::SUBSCRIPTION_LEVEL_NAMES[level]} subscription or better required)."
    redirect_back_or_to(current_user ? my_page_path : signin_path)
Severity: Minor
Found in app/controllers/application_controller.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 missing_badge_requirements has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def missing_badge_requirements
    require_section_type Constants::YOUTH_SECTIONS
    require_osm_permission(:read, :badge)
    return if performed? # The above either redirected or rendered

Severity: Minor
Found in app/controllers/reports_controller.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 password_complexity has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def password_complexity
    minimum_haystack = (10**14) # Withstand for 1 second of a massive cracking array
    pass = send(sorcery_config.password_attribute_name)

    alphabet_size = 0
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

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

  def html_from_log_lines(lines)
    content_tag :ol do
      lines.each do |line|
        next line if line.empty?
        if line.is_a?(Array)
Severity: Minor
Found in app/helpers/application_helper.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 (hours > 0) {
            formatted = hours + ' hours  ';
          }
Severity: Major
Found in app/assets/javascripts/programme_review/balanced.js - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                    if badge_data.mark_due(user.osm_api)
                      member_lines.push "Marked the \"#{badge.name}\" badge as due."
                    else
                      member_lines.push "Couldn't mark the \"#{badge.name}\" badge as due."
                      errors.push "Couldn't mark badge as due for \"#{badge.name}\" & \"#{member.name}\"."
    Severity: Major
    Found in app/models/automation_task_leadership.rb - About 45 mins to fix

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

        def get_data
          data = []
          earliest = Date.current.to_date
          latest = configuration[:the_next_n_weeks].weeks.from_now.to_date
      
      
      Severity: Minor
      Found in app/models/email_reminder_item_programme.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

      Function drawChart has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      function drawChart(data, labels, options, chart, z_or_m, n_or_t) {
      Severity: Minor
      Found in app/assets/javascripts/programme_review/balanced.js - About 45 mins to fix

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

          def yes_no(value, positive_value=true)
            if positive_value == value
              return "<span style=\"color: green;\">#{value ? 'yes' : 'no'}</span>".html_safe
            else
              return "<span style=\"color: red;\">#{value ? 'YES' : 'NO'}</span>".html_safe
        Severity: Minor
        Found in app/helpers/application_helper.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

                      rescue Osm::Error => exception
                        member_lines.push "Couldn't mark the \"#{badge.name}\" badge as due. OSM said \"#{exception.message}\"."
                        errors.push "Couldn't mark badge as due for \"#{badge.name}\" & \"#{member.name}\". OSM said \"#{exception.message}\"."
        Severity: Major
        Found in app/models/automation_task_leadership.rb - About 45 mins to fix

          Consider simplifying this complex logical expression.
          Open

              if params[:waiting]
                if PlannedBadgeRequirementsReport.data_for?(
                  current_user.id,
                  current_section.id,
                  start: dates.first,
          Severity: Major
          Found in app/controllers/reports_controller.rb - About 40 mins to fix

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

              def self.email_announcement(id)
                announcement = find(id)
            
                # Mailgun limits us to 100 message per hour.
                # So queue 1 per minute to trikle them out in batches when the worker runs.
            Severity: Minor
            Found in app/models/announcement.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_each has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def validate_each(object, attribute, value)
                value = value.to_s unless value.is_a?(String)
                if !options[:allow_blank] && value.blank?
                  unless value =~ /\A[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[0-1])\Z/
                    object.errors.add(attribute, :date_format, options)
            Severity: Minor
            Found in lib/date_format_validator.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 deliver_reset_password_instructions! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def deliver_reset_password_instructions!(options={})
                config = sorcery_config
                # hammering protection
                return false if config.reset_password_time_between_emails.present? && self.send(config.reset_password_email_sent_at_attribute_name) && self.send(config.reset_password_email_sent_at_attribute_name) > config.reset_password_time_between_emails.seconds.ago.utc
                self.class.sorcery_adapter.transaction do
            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 flatten_hash has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def flatten_hash(hash, base_key='')
                out = {}
                hash.each do |key, value|
                  key = "#{base_key}_#{key}" unless base_key.empty?
                  if value.is_a?(Hash)
            Severity: Minor
            Found in app/controllers/status_controller.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 text_from_log_lines has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def text_from_log_lines(lines, level=0)
                output = ''
                bullets = "*+>-"
                lines.each do |line|
                  next line if line.empty?
            Severity: Minor
            Found in app/helpers/application_helper.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 cache has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def cache
                return @cache unless @cache.nil?
                redis = Rails.cache.redis
                info = redis.info
                cache_attempts = info['keyspace_hits'].to_i + info['keyspace_misses'].to_i
            Severity: Minor
            Found in app/models/status.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 multiple_get_addresses has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def multiple_get_addresses(lists)
                lists = clean_lists(lists)
                @email_lists = current_user.email_lists.find(lists).sort{ |a, b|
                  section_a = Osm::Section.get(osm_api, a.section_id)
                  section_b = Osm::Section.get(osm_api, b.section_id)
            Severity: Minor
            Found in app/controllers/email_lists_controller.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

            Avoid too many return statements within this method.
            Open

                return ordinalized_date(time, '%H:%M on %-d %B %Y')
            Severity: Major
            Found in app/helpers/application_helper.rb - About 30 mins to fix
              Severity
              Category
              Status
              Source
              Language