mysociety/alaveteli

View on GitHub

Showing 277 of 433 total issues

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

  def check_in_post_redirect
    if params[:post_redirect]
      if session[:post_redirect_token]
        post_redirect =
          PostRedirect.find_by_token(session[:post_redirect_token])
Severity: Minor
Found in app/controllers/application_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 run_job has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def self.run_job(job, flush, verbose)
    if verbose
      STDOUT.puts("ActsAsXapian.update_index #{job.action} #{job.model} #{job.model_id} #{Time.now}")
    end

Severity: Minor
Found in lib/acts_as_xapian/acts_as_xapian.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 check_role_requirements has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def check_role_requirements
    role_names = Role.
                   where(id: params[:admin_user][:role_ids]).
                     pluck(:name).map(&:to_sym)
    missing_required = Hash.new { |h, k| h[k] = [] }
Severity: Minor
Found in app/controllers/admin_user_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 set_show_requests has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def set_show_requests
    # Use search query for this so can collapse and paginate easily
    # TODO: really should just use SQL query here rather than Xapian.

    @request_states = assign_request_states(@display_user)
Severity: Minor
Found in app/controllers/user_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 show_about_me? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def show_about_me?
    return true if @is_you
    return false unless @display_user.get_about_me_for_html_display.present?
    return false unless @display_user.active?
    return true if @display_user.confirmed_not_spam?
Severity: Minor
Found in app/controllers/user_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 destroy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def destroy
    begin
      @customer = current_user.pro_account.try(:stripe_customer)
      raise ActiveRecord::RecordNotFound unless @customer

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

    def results
      # If they've already pulled out the results, just return them.
      return cached_results unless cached_results.nil?

      docs = []
Severity: Minor
Found in lib/acts_as_xapian/acts_as_xapian.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 check_for_env_vars has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def check_for_env_vars(env_vars, example)
    missing = []
    env_vars.each do |env_var|
      missing << env_var unless ENV[env_var]
    end
Severity: Minor
Found in lib/tasks/usage.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 csv_export has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def self.csv_export(model, to_run, query=nil, header=nil, override={}, header_map={})
    return unless is_required?(model.name, to_run)

    # set query and header to default values unless supplied
    query  ||= model
Severity: Minor
Found in lib/data_export.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 user_name_slug has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def user_name_slug
    if is_external?
      if external_user_name.nil?
        fake_slug = "anonymous"
      else
Severity: Minor
Found in app/models/info_request.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

Function d3TimeSeries has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

function d3TimeSeries(selector, data, title, metric_name) {

  // Add the title
  var wrapper_element = document.querySelectorAll(selector)[0];

Severity: Minor
Found in app/assets/javascripts/time_series.js - 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 find_all_unknown_mime_types has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def self.find_all_unknown_mime_types
    IncomingMessage.find_each do |incoming_message|
      incoming_message.get_attachments_for_display.each do |attachment|
        if attachment.content_type.nil?
          raise "internal error incoming_message " + incoming_message.id.to_s
Severity: Minor
Found in app/models/incoming_message.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 cut_excerpt_part has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def cut_excerpt_part(part_position, part, separator, options)
    return "", "" unless part

    radius   = options.fetch(:radius, 100)
    omission = options.fetch(:omission, "...")
Severity: Minor
Found in app/helpers/highlight_helper.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 _convert_part_body_to_text has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def _convert_part_body_to_text(part)
    if part.nil?
      text = "[ Email has no body, please see attachments ]"
    else
      # whatever kind of attachment it is, get the UTF-8 encoded text
Severity: Minor
Found in app/models/incoming_message.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 short_or_long_name has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def short_or_long_name
    if short_name.nil? || short_name.empty?
      name.nil? ? "" : name
    else
      short_name
Severity: Minor
Found in app/models/concerns/public_body_derived_fields.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 line has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def line(opts = {})
    _line = read_attribute(:line)

    if opts[:redact]
      _line = strip_syslog_prefix(_line)
Severity: Minor
Found in app/models/mail_server_log.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 get_body_for_html_display has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def get_body_for_html_display(collapse_quoted_sections = true)
    # Find the body text and remove emails for privacy/anti-spam reasons
    text = get_main_body_text_unfolded
    folded_quoted_text = get_main_body_text_folded

Severity: Minor
Found in app/models/incoming_message.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 get_present_file_extensions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def get_present_file_extensions
    ret = {}
    get_attachments_for_display.each do |attachment|
      ext = AlaveteliFileTypes.mimetype_to_extension(attachment.content_type)
      if ext.nil? && !attachment.filename.nil?
Severity: Minor
Found in app/models/incoming_message.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 user_link_for_request has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def user_link_for_request(request)
    if request.is_external?
      user_name = request.external_user_name || _("Anonymous user")
      if !request.external_url.nil?
        link_to user_name, request.external_url
Severity: Minor
Found in app/helpers/link_to_helper.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 track_list has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def track_list
    @view = params[:view]

    if @view == 'recent' || @view.nil? # the blank one for backwards compatibility
      @track_thing = TrackThing.create_track_for_all_new_requests
Severity: Minor
Found in app/controllers/track_controller.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

Severity
Category
Status
Source
Language