mysociety/alaveteli

View on GitHub
app/models/info_request_event.rb

Summary

Maintainability
D
2 days
Test Coverage

Class InfoRequestEvent has 49 methods (exceeds 20 allowed). Consider refactoring.
Open

class InfoRequestEvent < ApplicationRecord
  extend XapianQueries

  EVENT_TYPES = [
    'sent',
Severity: Minor
Found in app/models/info_request_event.rb - About 6 hrs to fix

    File info_request_event.rb has 445 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class InfoRequestEvent < ApplicationRecord
      extend XapianQueries
    
      EVENT_TYPES = [
        'sent',
    Severity: Minor
    Found in app/models/info_request_event.rb - About 6 hrs to fix

      Method params_for_jsonb has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        def params_for_jsonb(params)
          params.inject({}) do |memo, (k, v)|
            key = k.to_s
      
            # look for keys ending in `_id` and attempt to map to a Ruby class
      Severity: Minor
      Found in app/models/info_request_event.rb - About 3 hrs 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 display_status has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def display_status
          if is_incoming_message?
            status = calculated_state
            return status.nil? ? _("Response") : InfoRequest.get_status_description(status)
          end
      Severity: Minor
      Found in app/models/info_request_event.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 indexed_by_search? has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def indexed_by_search?
          if %w[sent followup_sent response comment].include?(event_type)
            return false unless info_request.indexed_by_search?
            if event_type == 'response' && !incoming_message.indexed_by_search?
              return false
      Severity: Minor
      Found in app/models/info_request_event.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 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 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 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

      Avoid too many return statements within this method.
      Open

            return true
      Severity: Major
      Found in app/models/info_request_event.rb - About 30 mins to fix

        There are no issues that match your filters.

        Category
        Status