mysociety/alaveteli

View on GitHub

Showing 277 of 434 total issues

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

  def body
    return @cached_body if @cached_body

    begin
      return file.download if masked?
Severity: Minor
Found in app/models/foi_attachment.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 get_previous_email_sent_to has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def get_previous_email_sent_to(info_request_event)
    last_email = nil
    info_request_events.each do |e|
      if ((info_request_event.is_sent_sort? && e.is_sent_sort?) || (info_request_event.is_followup_sort? && e.is_followup_sort?)) && e.outgoing_message_id == info_request_event.outgoing_message_id
        break if e.id == info_request_event.id
Severity: Minor
Found in app/models/info_request.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 data_and_draft_checks has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def data_and_draft_checks
    if data.nil?
      errors.add(:data, _("Please choose a file containing your photo."))
      return
    end
Severity: Minor
Found in app/models/profile_photo.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 confirm has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def confirm
    post_redirect = PostRedirect.find_by_email_token(params[:email_token])

    if post_redirect.nil? || !post_redirect.email_token_valid?
      render template: 'user/bad_token'
Severity: Minor
Found in app/controllers/users/confirmations_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 mass_tag has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def mass_tag
    lookup_query

    if params[:tag] && (params[:tag] != "")
      if params[:table_name] == 'exact'
Severity: Minor
Found in app/controllers/admin_public_body_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 authorise has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def authorise
    @subscription = current_user.pro_account.subscriptions.
      retrieve(params.require(:id))

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

  def contact
    # if they clicked remove for link to request/body, remove it
    if params[:remove]
      @last_request = nil
      cookies['last_request_id'] = nil
Severity: Minor
Found in app/controllers/help_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 signchangeemail has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def signchangeemail
    # "authenticated?" has done the redirect to signin page for us
    return unless authenticated? || ask_to_login(
      web: _('To change your email address used on {{site_name}}',
             site_name: site_name),
Severity: Minor
Found in app/controllers/user_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 import_csv has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def self.import_csv(csv, tag, tag_behaviour, dry_run, editor, available_locales = [])
Severity: Minor
Found in app/models/public_body.rb - About 45 mins to fix

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

      def valid_to_reply_to?
        email = from_email.try(:downcase)
    
        # check validity of email
        return false if email.nil? || !MySociety::Validate.is_valid_email(email)
    Severity: Minor
    Found in app/models/raw_email.rb - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

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

      def self.with_query(query, tag)
        like_query = "%#{query}%"
        has_first_letter = tag.size == 1
    
        underscore_locale = AlaveteliLocalization.locale
    Severity: Minor
    Found in app/models/public_body.rb - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

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

      def unmasked_body
        MailHandler.attachment_body_for_hexdigest(
          raw_email.mail,
          hexdigest: hexdigest
        )
    Severity: Minor
    Found in app/models/foi_attachment.rb - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method import_csv_from_file has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def self.import_csv_from_file(csv_filename, tag, tag_behaviour, dry_run, editor, available_locales = [])
    Severity: Minor
    Found in app/models/public_body.rb - About 45 mins to fix

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

        def set_described_state(new_state, set_by = nil, message = "")
          old_described_state = described_state
          ActiveRecord::Base.transaction do
            self.awaiting_description = false
            last_event = info_request_events.last
      Severity: Minor
      Found in app/models/info_request.rb - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

        def populate_from_ical_feed
          cal_file = open(ical_feed_url)
          cal_parser = Icalendar::Parser.new(cal_file)
          cals = cal_parser.parse
          cal = cals.first
      Severity: Minor
      Found in app/models/holiday_import.rb - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

        def get_main_body_text_part(leaves=[])
          leaves = foi_attachments if leaves.empty?
      
          # Find first part which is text/plain or text/html
          # (We have to include HTML, as increasingly there are mail clients that
      Severity: Minor
      Found in app/models/incoming_message.rb - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

        def explorable_in_datasette?(attachment)
          return false unless attachment.is_public?
          return false unless attachment.incoming_message.is_public?
          return false unless info_request_is_public?(attachment)
          return false unless attachment.content_type == 'text/csv'
      Severity: Minor
      Found in app/helpers/datasette_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

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

        def params_diff
          # split out parameters into old/new diffs, and other ones
          old_params = {}
          new_params = {}
          other_params = {}
      Severity: Minor
      Found in app/models/info_request_event.rb - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

        def create
          @reason = params[:reason]
          @message = params[:message] || ""
          if @reason.empty?
            flash[:error] = _("Please choose a reason")
      Severity: Minor
      Found in app/controllers/reports_controller.rb - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

        def password_and_format_of_email
          check_email_is_present_and_valid(:old_email)
      
          if errors[:old_email].blank?
            if !email_belongs_to_user?(old_email)
      Severity: Minor
      Found in app/validators/change_email_validator.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

      Severity
      Category
      Status
      Source
      Language