openaustralia/publicwhip

View on GitHub

Showing 57 of 57 total issues

Class Division has 41 methods (exceeds 20 allowed). Consider refactoring.
Open

class Division < ApplicationRecord
  # debate_gid is currently used to generate links to debates on openaustralia.org.au. It would be better
  # to use the debate_url field for that. Currently that's completely ignored as it's overridden
  # below.
  # TODO: Do a data migration so that the debate_url field is the openaustralia.org.au url and debate_gid can be removed
Severity: Minor
Found in app/models/division.rb - About 5 hrs to fix

    Method load! has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.load!(url)
          Rails.logger.info "Loading Popolo data from #{url}..."
          data = JSON.parse(URI.parse(url).open.read)
          people = data["persons"]
          vote_events = data["vote_events"]
    Severity: Minor
    Found in app/lib/data_loader/popolo.rb - About 4 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

    Class Person has 32 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Person < ApplicationRecord
      has_many :members, -> { order(entered_house: :desc) }, inverse_of: :person, dependent: :destroy
      has_many :policy_person_distances, dependent: :destroy
      has_many :offices, dependent: :destroy
      has_many :people_distances, foreign_key: :person1_id, dependent: :destroy, inverse_of: :person1
    Severity: Minor
    Found in app/models/person.rb - About 4 hrs to fix

      Class Member has 30 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class Member < ApplicationRecord
        # TODO: Remove source_gid from schema as it's not being used (but still loaded by the loaders)
        searchkick index_name: "tvfy_members_#{Settings.stage}"
        has_one :member_info, dependent: :destroy
        delegate :rebellions, :votes_attended, :votes_possible, :tells, to: :member_info, allow_nil: true
      Severity: Minor
      Found in app/models/member.rb - About 3 hrs to fix

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

          def free_vote?
            # Free votes from 2006 and onwards. This list from Appendix 3 of
            # http://parlinfo.aph.gov.au/parlInfo/search/display/display.w3p;query=Id%3A%22library%2Fprspub%2FCQOS6%22
            # TODO: Do we need to restrict this to only these parties? Are these votes free for all parties?
        
        
        Severity: Minor
        Found in app/models/whip.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 load! has 82 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def self.load!(url)
              Rails.logger.info "Loading Popolo data from #{url}..."
              data = JSON.parse(URI.parse(url).open.read)
              people = data["persons"]
              vote_events = data["vote_events"]
        Severity: Major
        Found in app/lib/data_loader/popolo.rb - About 3 hrs to fix

          Method load! has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.load!(from_date, to_date = nil)
                agent = Mechanize.new
          
                (from_date..(to_date || from_date)).each do |date|
                  House.australian.each do |house|
          Severity: Minor
          Found in app/lib/data_loader/debates.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 update_distance! has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
          Open

            def update_distance!
              absentstrong = 0
              absent = 0
              samestrong = 0
              same = 0
          Severity: Minor
          Found in app/models/policy_person_distance.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 load! has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

                def load!
                  Rails.logger.info "Reloading representatives and senators..."
                  agent = Mechanize.new
                  %w[representatives senators].each do |file|
                    Rails.logger.info "Loading #{file}..."
          Severity: Minor
          Found in app/lib/data_loader/members.rb - About 2 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

          Class DivisionXML has 23 methods (exceeds 20 allowed). Consider refactoring.
          Open

            class DivisionXML
              MAXIMUM_MOTION_TEXT_SIZE = 15000
          
              attr_accessor :division_xml, :house
          
          
          Severity: Minor
          Found in app/lib/data_loader/division_xml.rb - About 2 hrs to fix

            Method search has a Cognitive Complexity of 17 (exceeds 5 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 2 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 free_vote? has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def free_vote?
                # Free votes from 2006 and onwards. This list from Appendix 3 of
                # http://parlinfo.aph.gov.au/parlInfo/search/display/display.w3p;query=Id%3A%22library%2Fprspub%2FCQOS6%22
                # TODO: Do we need to restrict this to only these parties? Are these votes free for all parties?
            
            
            Severity: Minor
            Found in app/models/whip.rb - About 1 hr to fix

              Method load! has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def self.load!(from_date, to_date = nil)
                    agent = Mechanize.new
              
                    (from_date..(to_date || from_date)).each do |date|
                      House.australian.each do |house|
              Severity: Minor
              Found in app/lib/data_loader/debates.rb - About 1 hr to fix

                Method policy_version_sentence_text has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                  def policy_version_sentence_text(version)
                    case version.event
                    when "create"
                      name = version.changeset["name"].second
                      description = version.changeset["description"].second
                Severity: Minor
                Found in app/helpers/policies_helper.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 policy_version_sentence has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                  def policy_version_sentence(version)
                    changes = []
                
                    case version.event
                    when "create"
                Severity: Minor
                Found in app/helpers/policies_helper.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 show has 38 lines of code (exceeds 25 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 1 hr to fix

                  Method policy_version_sentence_text has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def policy_version_sentence_text(version)
                      case version.event
                      when "create"
                        name = version.changeset["name"].second
                        description = version.changeset["description"].second
                  Severity: Minor
                  Found in app/helpers/policies_helper.rb - About 1 hr to fix

                    Method load! has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                          def load!
                            Rails.logger.info "Reloading representatives and senators..."
                            agent = Mechanize.new
                            %w[representatives senators].each do |file|
                              Rails.logger.info "Loading #{file}..."
                    Severity: Minor
                    Found in app/lib/data_loader/members.rb - About 1 hr to fix

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

                        def self.update_all!
                          rebellions = all_rebellion_counts
                          tells = all_tells_counts
                          turnout = all_turnout_counts
                          possible_turnout = all_possible_turnout_counts
                      Severity: Major
                      Found in app/models/division_info.rb and 1 other location - About 1 hr to fix
                      app/models/member_info.rb on lines 6..21

                      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 59.

                      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

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

                        def self.update_all!
                          rebellions = all_rebellion_counts
                          tells = all_tells_counts
                          votes_attended = all_votes_attended_counts
                          votes_possible = all_votes_possible_counts
                      Severity: Major
                      Found in app/models/member_info.rb and 1 other location - About 1 hr to fix
                      app/models/division_info.rb on lines 17..28

                      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 59.

                      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

                      Severity
                      Category
                      Status
                      Source
                      Language