mysociety/alaveteli

View on GitHub

Showing 338 of 434 total issues

Avoid deeply nested control flow statements.
Open

        rescue
          $stderr.puts("Error processing zip file: #{$ERROR_INFO.inspect}")
Severity: Major
Found in lib/mail_handler.rb - About 45 mins to fix

    Method contact has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def contact
        return unless params[:submitted_contact_form]
    
        if @recaptcha_required && !verify_recaptcha
          flash.now[:error] = _('There was an error with the reCAPTCHA. ' \
    Severity: Minor
    Found in app/controllers/users/messages_controller.rb - About 45 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 password_and_format_of_email has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def password_and_format_of_email
        check_email_is_present_and_valid(:old_email)
    
        if errors[:old_email].blank?
          if !email_belongs_to_user?(old_email)
    Severity: Minor
    Found in app/validators/change_email_validator.rb - About 45 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 bulk_destroy has a Cognitive Complexity of 8 (exceeds 5 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 45 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_bodies has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def update_bodies
        @draft = current_user.draft_info_request_batches.
          find_by(id: update_bodies_params[:draft_id])
        case update_bodies_params[:action]
        when 'add-all'
    Severity: Minor
    Found in app/controllers/alaveteli_pro/draft_info_request_batches_controller.rb - About 45 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 alert_not_clarified_request has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.alert_not_clarified_request
        info_requests = InfoRequest.
                          where("awaiting_description = ?
                                 AND described_state = 'waiting_clarification'
                                 AND info_requests.updated_at < ?
    Severity: Minor
    Found in app/mailers/request_mailer.rb - About 45 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 destroy_and_rebuild_index has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def self.destroy_and_rebuild_index(model_classes, verbose = false, terms = true, values = true, texts = true, safe_rebuild = true)
    Severity: Minor
    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 45 mins to fix

      Method create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          @reason = params[:reason]
          @message = params[:message] || ""
          if @reason.empty?
            flash[:error] = _("Please choose a reason")
      Severity: Minor
      Found in app/controllers/reports_controller.rb - About 45 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 show has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def show
          respond_to do |format|
            format.html do
              @holding_pen = in_holding_pen?(@raw_email) ? true : false
      
      
      Severity: Minor
      Found in app/controllers/admin_raw_email_controller.rb - About 45 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

      Avoid deeply nested control flow statements.
      Open

                  raise "dry run mismatched real run" if !errors.empty?
      Severity: Major
      Found in app/controllers/admin_public_body_controller.rb - About 45 mins to fix

        Method get_tag_values has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_tag_values(tag_as_string)
              found = false
              results = []
              tags.each do |tag|
                if tag.name == tag_as_string
        Severity: Minor
        Found in lib/has_tag_string/has_tag_string.rb - About 45 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 poll_for_incoming_loop has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.poll_for_incoming_loop
            if AlaveteliConfiguration.production_mailer_retriever_method == 'pop'
              poller = new
              Rails.logger.info "Starting #{ poller } polling loop"
              loop do
        Severity: Minor
        Found in lib/alaveteli_mail_poller.rb - About 45 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 csv_export has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def self.csv_export(model, to_run, query=nil, header=nil, override={}, header_map={})
        Severity: Minor
        Found in lib/data_export.rb - About 45 mins to fix

          Consider simplifying this complex logical expression.
          Open

                elsif curr_state && (event.event_type == 'followup_sent' || event.event_type == 'sent') && event.described_state && (event.described_state == 'waiting_response' || event.described_state == 'internal_review')
                  # Followups can set the status to waiting response / internal
                  # review. Initial requests ('sent') set the status to waiting response.
          
                  # We want to store that in calculated_state state so it gets
          Severity: Major
          Found in app/models/info_request.rb - About 40 mins to fix

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

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

                      def perform(object, method = nil)
                        return object.expire if object.is_a?(InfoRequest)
                    
                        if object == InfoRequest && method == :all
                          enumerator = InfoRequest.all
                    Severity: Minor
                    Found in app/jobs/info_request_expire_job.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