mysociety/alaveteli

View on GitHub

Showing 421 of 434 total issues

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

  def accept_incoming?(email, raw_email_data)
    # See if new responses are prevented
    gatekeeper = ResponseGatekeeper.for(allow_new_responses_from, self)
    # Take action if the message looks like spam
    spam_checker = ResponseGatekeeper::SpamChecker.new
Severity: Minor
Found in app/models/info_request.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 track_search_query has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def track_search_query
    @query = params[:query_array]

    # TODO: more hackery to make alternate formats still work with query_array
    if /^(.*)\.json$/.match(@query)
Severity: Minor
Found in app/controllers/track_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 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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

      if ((this.value === 'normal' || this.value === 'backpage') && ($('#info_request_described_state').val() === 'not_foi' || $('#info_request_described_state').val() === 'vexatious')) {
        $(this).attr('title', 'The request will not be hidden unless you change the prominence.');
        $(this).tooltip('show');
        submit_button.attr('title', 'Warning! You are about to save this request without hiding it!');
        submit_button.tooltip();
Severity: Major
Found in app/assets/javascripts/admin/admin.js and 1 other location - About 1 hr to fix
app/assets/javascripts/admin/admin.js on lines 54..66

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

      if ((this.value === 'vexatious' || this.value === 'not_foi') && ($('#info_request_prominence').val() === 'normal' || $('#info_request_prominence').val() === 'backpage')) {
        $('#info_request_prominence').attr('title', 'The request will not be hidden unless you change the prominence.');
        $('#info_request_prominence').tooltip('show');
        submit_button.attr('title', 'Warning! You are about to save this request without hiding it!');
        submit_button.tooltip();
Severity: Major
Found in app/assets/javascripts/admin/admin.js and 1 other location - About 1 hr to fix
app/assets/javascripts/admin/admin.js on lines 71..83

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

    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

      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 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 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 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 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 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 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 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 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 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
                            Severity
                            Category
                            Status
                            Source
                            Language