openaustralia/publicwhip

View on GitHub

Showing 41 of 57 total issues

Method search has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def search
    @current_members = Member.current.map { |m| m.name.downcase }
    @mps = []
    @divisions = []

Severity: Minor
Found in app/controllers/home_controller.rb - About 1 hr to fix

    Method policy_division_version_sentence has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def policy_division_version_sentence(version)
        vote = policy_division_version_vote(version)
        division = policy_division_version_division(version)
        division_link = content_tag(:em, link_to(division.name, division_url_simple(division)))
        out = []
    Severity: Minor
    Found in app/helpers/policies_helper.rb - About 1 hr to fix

      Method category_words_sentence has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def category_words_sentence(category, person: nil, policy: nil)
          out = []
          if category == :not_enough
            # For this category we have to order the sentence differently because it doesn't have the
            # same structure as the other sentences
      Severity: Minor
      Found in app/helpers/policy_person_distances_helper.rb - About 1 hr to fix

        Function changeSubscribeButtons has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function changeSubscribeButtons(new_text, new_class_name) {
          // test environment
          if (!document.getElementsByClassName) return false;
          if (!document.getElementsByTagName) return false;
          if (!document.getElementsByClassName("subscribe-button-form")) return false;
        Severity: Minor
        Found in app/assets/javascripts/changeSubscribeButton.js - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                if votes
                  whip.aye_votes = votes[["aye", 0]] || 0
                  whip.aye_tells = votes[["aye", 1]] || 0
                  whip.no_votes = votes[["no", 0]] || 0
                  whip.no_tells = votes[["no", 1]] || 0
          Severity: Major
          Found in app/models/whip.rb - About 1 hr to fix

            Method index has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def index
                @years = (Division.order(:date).first.date.year..Division.order(:date).last.date.year).to_a
            
                begin
                  @date_start, @date_end, @date_range = date_range(params[:date])
            Severity: Minor
            Found in app/controllers/divisions_controller.rb - About 55 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 member_rebellion_record_sentence has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def member_rebellion_record_sentence(member)
                if member.person.rebellions_fraction.zero?
                  member.currently_in_parliament? ? "Never rebels" : "Never rebelled"
                else
                  # TODO: Should this be an absolute count rather than percentage?
            Severity: Minor
            Found in app/helpers/members_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 category_words_sentence has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def category_words_sentence(category, person: nil, policy: nil)
                out = []
                if category == :not_enough
                  # For this category we have to order the sentence differently because it doesn't have the
                  # same structure as the other sentences
            Severity: Minor
            Found in app/helpers/policy_person_distances_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

            Function changeSubscribeButtons has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            function changeSubscribeButtons(new_text, new_class_name) {
              // test environment
              if (!document.getElementsByClassName) return false;
              if (!document.getElementsByTagName) return false;
              if (!document.getElementsByClassName("subscribe-button-form")) return false;
            Severity: Minor
            Found in app/assets/javascripts/changeSubscribeButton.js - 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 majority_strength_in_words has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def majority_strength_in_words(division)
                if division.unanimous?
                  "unanimously"
                elsif division.tied?
                  ""
            Severity: Minor
            Found in app/helpers/divisions_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 show has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def show
                self.resource = resource_class.confirm_by_token(params[:confirmation_token])
                yield resource if block_given?
            
                if resource.errors.empty?
            Severity: Minor
            Found in app/controllers/confirmations_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 fraction_to_percentage_display has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def fraction_to_percentage_display(fraction)
                if fraction
                  percentage = fraction * 100
                  # Special handling for number very close to 0 or 100
                  # These are numbers that would get rounded to 0% or 100% but are not exactly that so we want
            Severity: Minor
            Found in app/helpers/application_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 overlap_dates has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def overlap_dates
                result = []
                person1.members.reorder(:entered_house).each do |member1|
                  person2.members.reorder(:entered_house).each do |member2|
                    r = PeopleDistance.overlap_dates_members(member1, member2)
            Severity: Minor
            Found in app/models/people_distance.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 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def index
                @sort = params[:sort]
                @house = params[:house]
            
                members = Member.current
            Severity: Minor
            Found in app/controllers/members_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 show_redirect has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def show_redirect
                member = if params[:mpid]
                           Member.find(params[:mpid])
                         elsif params[:id]
                           begin
            Severity: Minor
            Found in app/controllers/members_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

            Avoid too many return statements within this function.
            Open

                if (button.lastChild.nodeType !== 3) return false;
            Severity: Major
            Found in app/assets/javascripts/changeSubscribeButton.js - About 30 mins to fix

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

                def show
                  member1 = Member.find_with_url_params(house: params[:house], mpc: params[:mpc], mpn: params[:mpn])
                  member2 = Member.find_with_url_params(house: params[:house2], mpc: params[:mpc2], mpn: params[:mpn2])
                  return render "members/member_not_found", status: :not_found if member1.nil? || member2.nil?
              
              
              Severity: Minor
              Found in app/controllers/people_distances_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 vote_words has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def vote_words(vote)
                  if vote
                    if vote.rebellion?
                      "voted #{vote_display(vote.vote)}, rebelling against the #{vote.party_name}"
                    elsif vote.free_vote?
              Severity: Minor
              Found in app/helpers/votes_helper.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 load! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def self.load!
                    Rails.logger.info "Reloading offices..."
                    agent = Mechanize.new
                    ministers_xml = agent.get "#{Settings.xml_data_base_url}members/ministers.xml"
                    Rails.logger.info "Deleted #{Office.delete_all} offices"
              Severity: Minor
              Found in app/lib/data_loader/offices.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 randomise_people_voting_on_policy has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def randomise_people_voting_on_policy(policy)
                  distances = policy.policy_person_distances.currently_in_parliament.includes(:person, person: :members)
              
                  # Insert people into each category
                  people_category_table = {}
              Severity: Minor
              Found in app/helpers/policies_helper.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