mysociety/alaveteli

View on GitHub

Showing 328 of 434 total issues

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

  def explorable_in_datasette?(attachment)
    return false unless attachment.is_public?
    return false unless attachment.incoming_message.is_public?
    return false unless info_request_is_public?(attachment)
    return false unless attachment.content_type == 'text/csv'
Severity: Minor
Found in app/helpers/datasette_helper.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 params_diff has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def params_diff
    # split out parameters into old/new diffs, and other ones
    old_params = {}
    new_params = {}
    other_params = {}
Severity: Minor
Found in app/models/info_request_event.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 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 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 create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def create
    AlaveteliLocalization.with_locale(AlaveteliLocalization.default_locale) do
      if params[:change_request_id]
        @change_request = PublicBodyChangeRequest.find(params[:change_request_id])
      end
Severity: Minor
Found in app/controllers/admin_public_body_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 index has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def index
    @title ||= 'Listing users'

    @query = params[:query].try(:strip)

Severity: Minor
Found in app/controllers/admin_user_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

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

      def perform_search(models, query, sortby, collapse, per_page = 25, this_page = nil)
    Severity: Minor
    Found in app/controllers/application_controller.rb - About 45 mins to fix

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

        def self.update_index(flush = false, verbose = false)
          # STDOUT.puts("start of ActsAsXapian.update_index") if verbose
      
          # Before calling writable_init we have to make sure every model class has been initialized.
          # i.e. has had its class code loaded, so acts_as_xapian has been called inside it, and
      Severity: Minor
      Found in lib/acts_as_xapian/acts_as_xapian.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 redeliver has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def redeliver
          message_ids = params[:url_title].split(',').map(&:strip)
          previous_request = @incoming_message.info_request
          destination_request = nil
      
      
      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 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 ensure_masked has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def ensure_masked
          if @attachment.masked?
            yield
          else
            FoiAttachmentMaskJob.perform_later(@attachment)
      Severity: Minor
      Found in app/controllers/attachments_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 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 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

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

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

        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

        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

        Severity
        Category
        Status
        Source
        Language