mysociety/alaveteli

View on GitHub

Showing 331 of 436 total issues

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

  def each(&_block)
    to_enum(:each) unless block_given?

    yield prepare_dashboard_metrics

Severity: Minor
Found in app/services/info_request_batch_zip.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

          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

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

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

                  def create
                    begin
                      @pro_account = current_user.pro_account ||= current_user.build_pro_account
                
                      # Ensure previous incomplete subscriptions are cancelled to prevent them
                Severity: Minor
                Found in app/controllers/alaveteli_pro/subscriptions_controller.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

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

                      def update
                        old_title = @info_request.title
                        old_prominence = @info_request.prominence
                        old_prominence_reason = @info_request.prominence_reason
                        old_described_state = @info_request.described_state
                    Severity: Minor
                    Found in app/controllers/admin_request_controller.rb - About 1 hr to fix

                      Method authorise has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def authorise
                          @subscription = current_user.pro_account.subscriptions.
                            retrieve(params.require(:id))
                      
                          if !@subscription
                      Severity: Minor
                      Found in app/controllers/alaveteli_pro/subscriptions_controller.rb - About 1 hr to fix

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

                          def excerpt(text, phrase, options = {})
                            return unless text && phrase
                        
                            separator = options.fetch(:separator, nil) || ""
                            case phrase
                        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

                        Severity
                        Category
                        Status
                        Source
                        Language