mysociety/alaveteli

View on GitHub

Showing 328 of 434 total issues

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

  def handle_blocked_ip(user)
    if send_exception_notifications?
      msg = "Possible spam signup (ip_in_blocklist) from " \
            "#{user.email}: #{user_ip} (#{country_from_ip})"
      ExceptionNotifier.notify_exception(Exception.new(msg), env: request.env)
Severity: Minor
Found in app/controllers/user_controller.rb and 1 other location - About 45 mins to fix
app/controllers/request_controller.rb on lines 782..793

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 40.

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

  var lock = function lock() {
    $draft.find(removeButtonSelector)
          .prop('disabled', true)
          .attr('aria-disabled', true);
  };
app/assets/javascripts/alaveteli_pro/batch_authority_search/result.js on lines 16..20

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 48.

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

  var lock = function lock() {
    $results.find(submitButtonSelector)
            .prop('disabled', true)
            .attr('aria-disabled', true);
  };
app/assets/javascripts/alaveteli_pro/draft_batch_summary/body.js on lines 13..17

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 48.

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 user_message has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def user_message(from_user, recipient_user, from_user_url, subject, message)
Severity: Minor
Found in app/mailers/contact_mailer.rb - About 35 mins to fix

    Method _destroy_and_rebuild_index_safely has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def self._destroy_and_rebuild_index_safely(model_classes, verbose, terms, values, texts)
    Severity: Minor
    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 35 mins to fix

      Method fake_response has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def fake_response(info_request, from_user, message_body, attachment_name, attachment_content)
      Severity: Minor
      Found in app/mailers/request_mailer.rb - About 35 mins to fix

        Method process_data has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def self.process_data(filename, display_header, column_data, overrides, query)
        Severity: Minor
        Found in lib/data_export.rb - About 35 mins to fix

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

              if @users
                @xapian_users = perform_search([User], @query, @sortby, nil, 5)
                @users_per_page = @per_page
                @xapian_users_hits = @xapian_users.results.size
                @xapian_users_total_hits = @xapian_users.matches_estimated
          Severity: Minor
          Found in app/controllers/general_controller.rb and 1 other location - About 35 mins to fix
          app/controllers/general_controller.rb on lines 144..152

          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 36.

          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 @bodies
                @xapian_bodies = perform_search([PublicBody], @query, @sortby, nil, 5)
                @bodies_per_page = @per_page
                @xapian_bodies_hits = @xapian_bodies.results.size
                @xapian_bodies_total_hits = @xapian_bodies.matches_estimated
          Severity: Minor
          Found in app/controllers/general_controller.rb and 1 other location - About 35 mins to fix
          app/controllers/general_controller.rb on lines 153..161

          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 36.

          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 ensure_filename! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def ensure_filename!
              if filename.blank?
                calc_ext = AlaveteliFileTypes.mimetype_to_extension(content_type)
                calc_ext = "bin" unless calc_ext
                if !within_rfc822_subject.nil?
          Severity: Minor
          Found in app/models/foi_attachment.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 delivery_status has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def delivery_status
              unless attributes['delivery_status'].present?
                # attempt to parse the status from the log line and store if successful
                set_delivery_status
              end
          Severity: Minor
          Found in app/models/mail_server_log.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_info_request_described_state has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def set_info_request_described_state
              if status == 'failed'
                info_request.set_described_state('error_message')
              elsif message_type == 'initial_request'
                info_request.set_described_state('waiting_response')
          Severity: Minor
          Found in app/models/outgoing_message.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 do_track_url has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def do_track_url(track_thing, feed = 'track', options = {})
              if track_thing.track_type == 'request_updates'
                track_request_url(options.merge(url_title: track_thing.info_request.url_title, feed: feed))
              elsif track_thing.track_type == 'all_new_requests'
                track_list_url(options.merge(view: 'recent', feed: feed))
          Severity: Minor
          Found in app/helpers/link_to_helper.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 is_clarification? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def is_clarification?
              waiting_clarification = false
              # A follow up is a clarification only if it's the first
              # follow up when the request is in a state of
              # waiting for clarification
          Severity: Minor
          Found in app/models/info_request_event.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 update has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def update
              track_thing = TrackThing.find(params[:track_id].to_i)
          
              unless authenticated?(as: track_thing.tracking_user)
                ask_to_login(
          Severity: Minor
          Found in app/controllers/track_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 search_text_main has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def search_text_main(clipped = false)
              text = ''
              if event_type == 'sent'
                text = text + outgoing_message.get_text_for_indexing + "\n\n"
              elsif event_type == 'followup_sent'
          Severity: Minor
          Found in app/models/info_request_event.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 must_be_internal_or_external has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def must_be_internal_or_external
              # We must permit user_id and external_user_name both to be nil, because the system
              # allows a request to be created by a non-logged-in user.
              if user_id
                unless external_user_name.nil?
          Severity: Minor
          Found in app/models/info_request.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 public_bodies has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.public_bodies
              per_graph = 10
              minimum_requests = AlaveteliConfiguration.minimum_requests_for_statistics
              # Make sure minimum_requests is > 0 to avoid division-by-zero
              minimum_requests = [minimum_requests, 1].max
          Severity: Minor
          Found in app/models/statistics.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 apply_filters has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def apply_filters(scope)
              @query = params[:query]
              return scope if @query.blank?
          
              name, value = HasTagString::HasTagStringTag.
          Severity: Minor
          Found in app/controllers/admin/tags_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 track_set has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def track_set
              if @user
                @existing_track = TrackThing.find_existing(@user, @track_thing)
                if @existing_track
                  flash[:notice] =
          Severity: Minor
          Found in app/controllers/track_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

          Severity
          Category
          Status
          Source
          Language