mysociety/alaveteli

View on GitHub

Showing 337 of 433 total issues

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

  def highlight_matches(text, phrases, options = {})
    if options.fetch(:sanitize, true)
      text = ActionController::Base.helpers.sanitize(text).try(:html_safe)
    end

Severity: Minor
Found in app/helpers/highlight_helper.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 move has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def move
    editor = admin_current_user

    if params[:commit] == 'Move request to user' && !params[:user_url_name].blank?
      destination_user = User.find_by_url_name(params[:user_url_name])
Severity: Minor
Found in app/controllers/admin_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 prepare_environment has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def self.prepare_environment
    return unless @@db_path.nil?

    # barf if we can't figure out the environment
    environment = (ENV['RAILS_ENV'] or Rails.env)
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 xapian_value has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def xapian_value(field, type = nil, index_translations = false)
      if index_translations && respond_to?("translations")
        if (type == :date) || (type == :boolean)
          value = single_xapian_value(field, type = type)
        else
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 log_overdue_event_type has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.log_overdue_event_type(event_type)
    date_field = case event_type
    when 'overdue'
      'date_response_required_by'
    when 'very_overdue'
Severity: Minor
Found in app/models/info_request.rb - About 1 hr to fix

    Method play has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def play
        session[:request_game] = Time.zone.now
    
        @missing = InfoRequest.
          where_old_unclassified.
    Severity: Minor
    Found in app/controllers/request_game_controller.rb - About 1 hr to fix

      Function load has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        that.load = function() {
          var cardError = document.getElementById('card-errors');
      
          // Sync initial state for terms checkbox and submit button
          that.submit.setAttribute('disabled', 'true');
      Severity: Minor
      Found in app/assets/javascripts/alaveteli_pro/stripe.js - About 1 hr to fix

        Method hidden_user_explanation has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def hidden_user_explanation
            prominence_reason = render_to_string(
              partial: "admin_request/hidden_user_explanation/#{params[:message]}",
              formats: [:text],
              locals: {
        Severity: Minor
        Found in app/controllers/services_controller.rb - About 1 hr to fix

          Method create_batch has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def create_batch
              @info_request_batch =
                InfoRequestBatch.find(params[:info_request_batch_id])
          
              authorize! :update, @info_request_batch
          Severity: Minor
          Found in app/controllers/alaveteli_pro/embargo_extensions_controller.rb - About 1 hr to fix

            Method make_request_summary_file has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def make_request_summary_file(info_request)
                done = false
                @render_to_file = true
                assign_variables_for_show_template(info_request)
                if HTMLtoPDFConverter.exist?
            Severity: Minor
            Found in app/controllers/request_controller.rb - About 1 hr to fix

              Method generate_upload_url has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def generate_upload_url
                  if params[:incoming_message_id]
                    incoming_message = IncomingMessage.find(params[:incoming_message_id])
                    email = incoming_message.from_email
                    name = incoming_message.safe_from_name || @info_request.public_body.name
              Severity: Minor
              Found in app/controllers/admin_request_controller.rb - About 1 hr to fix

                Method phases has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def self.phases
                      [
                        { capital_label: _('Awaiting response'),
                          label: _('awaiting response'),
                          scope: :awaiting_response,
                Severity: Minor
                Found in app/models/info_request/state.rb - About 1 hr to fix

                  Method load_file has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def self.load_file(file_name)
                      is_gz = file_name.include?(".gz")
                      file_name_db = is_gz ? file_name.gsub(".gz", "") : file_name
                  
                      modified = File.stat(file_name).mtime
                  Severity: Minor
                  Found in app/models/mail_server_log.rb - About 1 hr to fix

                    Method import_values_from_csv_row has 30 lines of code (exceeds 25 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

                      Method bulk_destroy has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def bulk_destroy
                          if params[:commit] == "No"
                            redirect_to(admin_request_url(params[:request_id]))
                          end
                      
                      
                      Severity: Minor
                      Found in app/controllers/admin_incoming_message_controller.rb - About 1 hr to fix

                        Method lookup_query has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def lookup_query
                            @locale = AlaveteliLocalization.locale
                            AlaveteliLocalization.with_locale(@locale) do
                              @query = params[:query]
                              @query = nil if @query == ""
                        Severity: Minor
                        Found in app/controllers/admin_public_body_controller.rb - About 1 hr to fix

                          Method get_status_from_params has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            def get_status_from_params(params)
                              query = ""
                              if params[:latest_status]
                                statuses = []
                                if params[:latest_status].class == String
                          Severity: Minor
                          Found in lib/xapian_queries.rb - About 1 hr to fix

                            Method attempt_to_find_original_attachment_attributes has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                  def attempt_to_find_original_attachment_attributes(mail, body:, nested: false)
                                    all_attributes = get_attachment_attributes(mail)
                            
                                    def calculate_hexdigest(body)
                                      # ensure bodies have the same line endings and are encoded the same
                            Severity: Minor
                            Found in lib/mail_handler/backends/mail_backend.rb - About 1 hr to fix

                              Method _destroy_and_rebuild_index_safely has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                def self._destroy_and_rebuild_index_safely(model_classes, verbose, terms, values, texts)
                                  batch_size = 1000
                                  model_classes.each do |model_class|
                                    model_class_count = model_class.count
                                    0.step(model_class_count, batch_size) do |i|
                              Severity: Minor
                              Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

                                Method phase has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                      def phase(cached_value_ok=false)
                                        if @info_request.awaiting_description?
                                          :response_received
                                        else
                                          state = @info_request.calculate_status(cached_value_ok)
                                Severity: Minor
                                Found in app/models/info_request/state/calculator.rb - About 1 hr to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language