mysociety/alaveteli

View on GitHub

Showing 277 of 433 total issues

Method download_entire_request has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def download_entire_request
    AlaveteliLocalization.with_locale(locale) do
      @info_request = InfoRequest.find_by_url_title!(params[:url_title])
      # Check for access and hide emargoed requests immediately, so that we
      # don't leak any info to people who can't access them
Severity: Minor
Found in app/controllers/request_controller.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 import_values_from_csv_row has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def import_values_from_csv_row(row, line, name, options)
    is_new = new_record?
    edit_info = if is_new
      { action: "creating new authority",
        comment: 'Created from spreadsheet' }
Severity: Minor
Found in app/models/public_body.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 display_status has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def display_status
    if is_incoming_message?
      status = calculated_state
      return status.nil? ? _("Response") : InfoRequest.get_status_description(status)
    end
Severity: Minor
Found in app/models/info_request_event.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 init_terms has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def self.init_terms(terms)
    terms.each do |_method, term_code, prefix|
      unless term_code.match(/^[A-Z]$/)
        raise "Use a single capital letter for term code"
      end
Severity: Minor
Found in lib/acts_as_xapian/acts_as_xapian.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 body_request_events has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def body_request_events
    feed_type = params[:feed_type]
    if @public_body.id != params[:id].to_i
      raise PermissionDenied, "#{@public_body.id} != #{params[:id]}"
    end
Severity: Minor
Found in app/controllers/api_controller.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 words_to_highlight has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def words_to_highlight(opts = {})
      default_opts = { include_original: false, regex: false }
      opts = default_opts.merge(opts)

      # Reject all prefixes other than Z, which we know is reserved for stems
Severity: Minor
Found in lib/acts_as_xapian/acts_as_xapian.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 tnef_attachments has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def tnef_attachments(content)
    attachments = []
    Dir.mktmpdir do |dir|
      IO.popen("tnef -K -C #{dir} 2> /dev/null", "wb") do |f|
        f.write(content)
Severity: Minor
Found in lib/mail_handler.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 is_oof? has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def self.is_oof?(message)
      # Check for out-of-office

      if MailHandler.get_header_string("X-POST-MessageClass", message) == "9; Autoresponder"
        return true
Severity: Minor
Found in lib/mail_handler/reply_handler.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 event_description has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def event_description(event)
    body_link = public_body_link_absolute(event.info_request.public_body)
    user_link = request_user_link_absolute(event.info_request)
    date = simple_date(event.created_at)
    case event.event_type
Severity: Minor
Found in app/helpers/application_helper.rb - About 1 hr to fix

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

      def redeliver
        message_ids = params[:url_title].split(',').map(&:strip)
        previous_request = @incoming_message.info_request
        destination_request = nil
    
    
    Severity: Minor
    Found in app/controllers/admin_incoming_message_controller.rb - About 1 hr to fix

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

        def wall
          long_cache
          @display_user = set_display_user
          @is_you = current_user_is_display_user
          feed_results = Set.new
      Severity: Minor
      Found in app/controllers/user_controller.rb - About 1 hr to fix

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

          def signup
            # Make the user and try to save it
            @user_signup = User.new(user_params(:user_signup))
            error = false
            if @request_from_foreign_country && !verify_recaptcha
        Severity: Minor
        Found in app/controllers/user_controller.rb - About 1 hr to fix

          Method update has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def update
              @pretoken_redirect = PostRedirect.find_by(token: @pretoken) if @pretoken
          
              if @password_change_user
                @password_change_user.password = params[:password_change_user][:password]
          Severity: Minor
          Found in app/controllers/password_changes_controller.rb - About 1 hr to fix

            Method remove_quoted_sections has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.remove_quoted_sections(text, replacement = "FOLDED_QUOTED_SECTION")
                text = text.dup
                replacement = "\n" + replacement + "\n"
            
                # First do this peculiar form of quoting, as the > single line quoting
            Severity: Minor
            Found in app/models/incoming_message.rb - About 1 hr to fix

              Method alert_not_clarified_request has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def self.alert_not_clarified_request
                  info_requests = InfoRequest.
                                    where("awaiting_description = ?
                                           AND described_state = 'waiting_clarification'
                                           AND info_requests.updated_at < ?
              Severity: Minor
              Found in app/mailers/request_mailer.rb - About 1 hr to fix

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

                  def assign_variables_for_show_template(info_request)
                    @info_request = info_request
                    @status = info_request.calculate_status
                    @old_unclassified =
                      info_request.is_old_unclassified? && authenticated?
                Severity: Minor
                Found in app/controllers/request_controller.rb - About 1 hr to fix

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

                    def hide
                      ActiveRecord::Base.transaction do
                        subject = params[:subject]
                        explanation = params[:explanation]
                  
                  
                  Severity: Minor
                  Found in app/controllers/admin_request_controller.rb - About 1 hr to fix

                    Method stop_new_responses_on_old_requests has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def self.stop_new_responses_on_old_requests
                        # 'old' months since last change to request, only allow new incoming
                        # messages from authority domains
                        InfoRequest.
                          been_published.
                    Severity: Minor
                    Found in app/models/info_request.rb - About 1 hr to fix

                      Method alert_new_response_reminders_internal has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def self.alert_new_response_reminders_internal(days_since, type_code)
                          info_requests = InfoRequest.
                            where_old_unclassified(days_since).
                              where(use_notifications: false).
                                order(:id).
                      Severity: Minor
                      Found in app/mailers/request_mailer.rb - About 1 hr to fix

                        Method show has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def show
                            medium_cache
                            AlaveteliLocalization.with_locale(locale) do
                              # Test for whole request being hidden
                              return render_hidden if cannot?(:read, @info_request)
                        Severity: Minor
                        Found in app/controllers/request_controller.rb - About 1 hr to fix
                          Severity
                          Category
                          Status
                          Source
                          Language