opengovernment/askthem

View on GitHub

Showing 84 of 154 total issues

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

  def officials_by_state_and_office(state_id, office_ids)
    office_ids.each_with_index do |office_id, index|
      begin
        state_id = state_id == 'us' ? 'NA' : state_id.upcase
        return get('Officials.getByOfficeState',
Severity: Minor
Found in lib/project_vote_smart.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 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def perform(id)
    question = Question.find(id)
    user = question.user

    if user && question.coordinates.blank?
Severity: Minor
Found in app/workers/question_coordinates_worker.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 office_ids has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def office_ids(options)
    # Chairman, Councilmember
    return [347, 368] if options[:state] == 'dc'

    office_ids = []
Severity: Minor
Found in lib/project_vote_smart.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

Consider simplifying this complex logical expression.
Open

      return session if session_details[session].key?("type") && session_details[session]["type"] == type ||
        type == "primary" && !session_details[session]["display_name"][/Budget|Called|Extraordinary|Fiscal|Special/] ||
        type == "special" &&  session_details[session]["display_name"][/Budget|Called|Extraordinary|Fiscal|Special/]
Severity: Major
Found in app/models/metadatum.rb - About 40 mins to fix

    Consider simplifying this complex logical expression.
    Open

          if (width.blank? || height.blank?) ||
            (opts[:state] && opts[:state] == Metadatum::Unaffiliated::ABBREVIATION) ||
            api_key.blank? ||
            Rails.env.development?
    
    
    Severity: Major
    Found in app/helpers/application_helper.rb - About 40 mins to fix

      Method find_site_key_and_video_id has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def find_site_key_and_video_id
          VIDEO_SITE_URL_PATTERNS.each do |key, value|
            value.each do |pattern|
              if original_url =~ pattern
                key = :youtube_full if key == :youtube
      Severity: Minor
      Found in app/models/video_src_url.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 new has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def new
          new! do
            if params[:twitter_id]
              screen_name = params[:twitter_id]
              twitter_api = TwitterPersonService.new(screen_name, false)
      Severity: Minor
      Found in app/controllers/candidates_controller.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 most_recent_session has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def most_recent_session(type)
          session_details = read_attribute(:session_details)
          read_attribute(:terms).last["sessions"].reverse.each do |session|
            # OpenStates doesn't always declare the session type.
            return session if session_details[session].key?("type") && session_details[session]["type"] == type ||
      Severity: Minor
      Found in app/models/metadatum.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 state_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def state_name
          if state? || federal?
            @jurisdiction['name']
          elsif local?
            state = Metadatum.where(abbreviation: state_abbreviation).first
      Severity: Minor
      Found in app/helpers/application_helper.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 legacy_skip_for_now has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def legacy_skip_for_now(office, division)
          (office.level == "county" && (office.name.downcase != "mayor" &&
                                        !office.name.downcase.include?("council"))) ||
            (office.level == "federal" && division.scope == "national") ||
            ((office.level == "city" || office.level == "other") &&
      Severity: Minor
      Found in app/models/cached_officials_from_google.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(id)
          self.person = Person.find(id.to_s)
          return unless person.photo_url.present?
      
          unless ImageLinkChecker.new(person.photo_url).accessible?
      Severity: Minor
      Found in app/workers/person_check_photo_url_worker.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 function.
      Open

                return options.messages.even;
      Severity: Major
      Found in app/assets/javascripts/rails.validations.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                  return options.message;
        Severity: Major
        Found in app/assets/javascripts/rails.validations.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return;
          Severity: Major
          Found in app/assets/javascripts/rails.validations.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                      return options.messages.odd;
            Severity: Major
            Found in app/assets/javascripts/rails.validations.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return options.messages[check];
              Severity: Major
              Found in app/assets/javascripts/rails.validations.js - About 30 mins to fix

                Method id has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def id
                    raise "Must specify state" unless state
                    raise "Only municipality or county, not both" if municipality && county
                
                    id = state.downcase
                Severity: Minor
                Found in app/models/jurisdiction_id.rb - About 25 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 new has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def new
                    set_up_steps
                    @question = Question.new(state: @state_code)
                    @question.user = user_signed_in? ? current_user : User.new
                    @question.user.for_new_question = true
                Severity: Minor
                Found in app/controllers/questions_controller.rb - About 25 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 copy_to_new_person has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def copy_to_new_person
                    unless Metadatum.where(id: state).first
                      copy_to_new_metadatum
                    end
                
                
                Severity: Minor
                Found in app/models/cached_official.rb - About 25 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 guess_office_level has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def guess_office_level(office, division)
                    if office.is_governor? || office.is_state_legislator?
                      GoogleCivicInfo::Office::STATE
                    elsif office.is_federal_legislator? || office.is_federal_executive_or_judicial?
                      GoogleCivicInfo::Office::FEDERAL
                Severity: Minor
                Found in app/models/cached_officials_from_google.rb - About 25 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