mysociety/alaveteli

View on GitHub

Showing 420 of 433 total issues

Method add_correspondence has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def add_correspondence
    json = ActiveSupport::JSON.decode(params[:correspondence_json])
    attachments = params[:attachments]

    direction = json["direction"]
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 expand_and_normalize_parts has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

      def expand_and_normalize_parts(part, parent_mail)
        if part.multipart?
          Mail::PartsList.new(part.parts.each { |sub_part| expand_and_normalize_parts(sub_part, parent_mail) })
        else
          part_filename = get_part_file_name(part)
Severity: Minor
Found in lib/mail_handler/backends/mail_backend.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 list has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def list
    long_cache

    @tag = params[:tag] || 'all'
    @tag = @tag.upcase if @tag.scan(/./mu).size == 1
Severity: Minor
Found in app/controllers/public_body_controller.rb - About 1 hr to fix

    Method new has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def new
        if params[:comment]
          # TODO: this check should theoretically be a validation rule in the model
          @existing_comment = Comment.find_existing(@info_request.id, params[:comment][:body])
        else
    Severity: Minor
    Found in app/controllers/comment_controller.rb - About 1 hr to fix

      Method create_fixtures has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.create_fixtures(fixtures_directory, fixture_set_names, class_names = {}, config = ActiveRecord::Base)
            fixture_set_names = Array(fixture_set_names).map(&:to_s)
            class_names = ClassCache.new class_names, config
      
            # FIXME: Apparently JK uses this.
      Severity: Minor
      Found in lib/no_constraint_disabling.rb - About 1 hr to fix

        Method results has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def results
              # If they've already pulled out the results, just return them.
              return cached_results unless cached_results.nil?
        
              docs = []
        Severity: Minor
        Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

          Function stripeForm has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          function stripeForm(form, options) {
            var that = Object.assign({
              stripe: Stripe(AlaveteliPro.stripe_publishable_key),
              form: form,
              submit: document.getElementById('js-stripe-submit'),
          Severity: Minor
          Found in app/assets/javascripts/alaveteli_pro/stripe.js - 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 receive has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            def receive(email, raw_email_data, *args)
              return if already_received?(email)
          
              defaults = { override_stop_new_responses: false,
                           rejected_reason: nil,
          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 get_attachment_text_from_zip_file has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            def get_attachment_text_from_zip_file(zip_file)
              text = ""
              zip_file.each do |entry|
                if entry.file?
                  filename = entry.to_s
          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 normalize_string_to_utf8 has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          def normalize_string_to_utf8(s, suggested_character_encoding=nil)
            # Make a list of encodings to try:
            to_try = []
          
            guessed_encoding = if CharlockHolmes::EncodingDetector.detect(s).blank?
          Severity: Minor
          Found in lib/normalize_string.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 process_data has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.process_data(filename, display_header, column_data, overrides, query)
              CSV.open(filename, "wb") do |csv|
                csv << display_header
                find_each_record(query) do |model_instance|
                  line = []
          Severity: Minor
          Found in lib/data_export.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 attempt_to_find_original_attachment_attributes has a Cognitive Complexity of 14 (exceeds 5 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

          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 43 lines of code (exceeds 25 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 1 hr to fix

            Method start has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.start(opt={})
                opt = DEFAULTS.dup.merge(opt)
            
                Thread.new do
                  prev = Hash.new(0)
            Severity: Minor
            Found in lib/memory_profiler.rb - About 1 hr to fix

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

                  def self.alert_expiring
                    expiring_info_requests =
                      InfoRequest.
                        embargo_expiring.
                          where(use_notifications: false).
              Severity: Major
              Found in app/mailers/alaveteli_pro/embargo_mailer.rb and 1 other location - About 1 hr to fix
              app/mailers/alaveteli_pro/embargo_mailer.rb on lines 38..63

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

              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

                  def self.alert_expired
                    expired_info_requests =
                      InfoRequest.
                        embargo_expired_today.
                          where(use_notifications: false).
              Severity: Major
              Found in app/mailers/alaveteli_pro/embargo_mailer.rb and 1 other location - About 1 hr to fix
              app/mailers/alaveteli_pro/embargo_mailer.rb on lines 8..33

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

              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 (state == "unchecked") {
                    selectables.each(function () {
                      $(this).prop('checked', true);
                    });
              
              
              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 108..116

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

              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

                  } else {
                    selectables.each(function () {
                      $(this).prop('checked', false);
                    });
              
              
              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 100..108

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

              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 status_description has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def status_description(info_request, status)
                  case status
                  when 'waiting_classification'
                    _('Awaiting classification')
                  when 'waiting_response'
              Severity: Minor
              Found in app/helpers/widget_helper.rb - About 1 hr to fix

                Method import_csv has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def import_csv
                    @notes = ""
                    @errors = ""
                    if request.post?
                      dry_run_only = params['commit'] != 'Upload'
                Severity: Minor
                Found in app/controllers/admin_public_body_controller.rb - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language