scottwillson/racing_on_rails

View on GitHub

Showing 333 of 1,278 total issues

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

  def compare_by_most_recent_result(x, y)
    return 0 if none?(x.scores, y.scores)

    # Sort scores by most recent date, lowest place
    # "Best" scores last because #pop returns the last item
Severity: Minor
Found in app/models/competitions/calculations/place.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 calculate! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def self.calculate!(year = Time.zone.today.year)
        ActiveSupport::Notifications.instrument "calculate.#{name}.competitions.racing_on_rails" do
          transaction do
            series = Series.where(name: parent_event_name).year(year).first

Severity: Minor
Found in app/models/competitions/grand_prix_brad_ross/team_standings.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 calculate! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def self.calculate!(year = Time.zone.today.year)
      ActiveSupport::Notifications.instrument "calculate.#{name}.competitions.racing_on_rails" do
        transaction do
          parent = ::WeeklySeries.year(year).where(name: parent_event_name).first

Severity: Minor
Found in app/models/competitions/blind_date_at_the_dairy_monthly_standings.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 categories_for has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def categories_for(race)
        categories = [race.category] + race.category.descendants

        if race.category.name == "Masters Men"
          masters_men_4_5 = ::Category.find_by(name: "Masters Men 4/5")
Severity: Minor
Found in app/models/competitions/overall_bars/categories.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 compare_by_most_recent_place has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def compare_by_most_recent_place(other)
      dates = Set.new(scores + other.scores) { |score| score.source_result.date }.to_a
      dates.sort!.reverse!
      dates.each do |date|
        score = scores.detect { |s| s.source_result.event.date == date }
Severity: Minor
Found in app/models/results/comparison.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 hometown has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def hometown
    if city.blank?
      if state.blank?
        ""
      elsif state == RacingAssociation.current.state
Severity: Minor
Found in app/models/person.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 calculate! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def self.calculate!(year = Time.zone.today.year)
      ActiveSupport::Notifications.instrument "calculate.#{name}.competitions.racing_on_rails" do
        transaction do
          year = year.to_i if year.is_a?(String)
          date = Date.new(year, 1, 1)
Severity: Minor
Found in app/models/competitions/mbra_team_bar.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 points_for_place has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

        def self.points_for_place(source_result, points_for_place, place_by, result_place, results_size)
          return 0 unless source_result.placed?

          if place_by == "place"
            return 0 if result_place == Float::INFINITY
Severity: Minor
Found in app/models/calculations/v3/steps/assign_points.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 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    @person.password = params[:person][:password]

    if @person.password.blank?
      flash[:warn] = "Please provide a new password"
Severity: Minor
Found in app/controllers/password_resets_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 normalize_ability_punctuation has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def self.normalize_ability_punctuation(name)
        # Don't combine Junior Men 9-12 3/4/5
        return name if name[%r{\d-1\d \d/\d/\d}]

        5.downto(2).each do |length|
Severity: Minor
Found in app/models/categories/name_normalization.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 set_membership_dates has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def set_membership_dates
      if member_from && member_to.nil?
        self.member_to = Time.zone.local(member_from.year).end_of_year
      elsif member_from.nil? && member_to
        self.member_from = Time.zone.today if member_from.nil?
Severity: Minor
Found in app/models/people/membership.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 results_table has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def results_table(event, race, results = nil)
    return "" unless race

    table = Tabular::Table.new

Severity: Minor
Found in app/helpers/results_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 labelled_text has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def labelled_text(object_name, method, label_text = nil, text = nil, label_options = {}, _text_class = nil)
Severity: Minor
Found in app/helpers/racing_on_rails/form_tag_helper.rb - About 45 mins to fix

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

        def upload
          uploaded_file = params[:results_file]
    
          path = "#{Dir.tmpdir}/#{uploaded_file.original_filename}"
          File.open(path, "wb") do |f|
    Severity: Minor
    Found in app/controllers/admin/events_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 assert_equal_dates has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def assert_equal_dates(expected, actual, message = nil, format = "%Y-%m-%d")
        expected = expected.strftime(format) if !expected.nil? && (expected.is_a?(Date) || expected.is_a?(DateTime) || expected.is_a?(Time))
        formatted_actual = actual
        formatted_actual = actual.strftime(format) if !actual.nil? && (actual.is_a?(Date) || actual.is_a?(DateTime) || actual.is_a?(Time))
        flunk("#{message} \nExpected #{expected} \nbut was #{formatted_actual}") unless expected == formatted_actual
    Severity: Minor
    Found in test/test_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

    Consider simplifying this complex logical expression.
    Open

          if frozen?
            self[:team_competition_result] ||
              event.is_a?(::Competitions::TeamBar) ||
              event.is_a?(::Competitions::CrossCrusadeTeamCompetition) ||
              event.is_a?(::Competitions::MbraTeamBar)
    Severity: Major
    Found in app/models/results/competitions.rb - About 40 mins to fix

      Consider simplifying this complex logical expression.
      Open

          if !new_record? &&
             previous_name.present? &&
             name.present? &&
             previous_name.casecmp(name) != 0 &&
             !Alias.exists?(name: previous_name, aliasable_id: id, aliasable_type: "Team") &&
      Severity: Major
      Found in app/models/team.rb - About 40 mins to fix

        Consider simplifying this complex logical expression.
        Open

                    next if !weekday?(source_result.event) ||
                            (calculator.calculations_events.include?(source_result.event) && source_result.event.points?) ||
                            omnium_or_stage_race?(source_result.event.parent) ||
                            omnium_or_stage_race?(source_result.event) ||
                            series_overall?(source_result.event)
        Severity: Major
        Found in app/models/calculations/v3/steps/reject_weekday_events.rb - About 40 mins to fix

          Consider simplifying this complex logical expression.
          Open

                if !new_record? &&
                   previous_name.present? &&
                   name.present? &&
                   previous_name.casecmp(name) != 0 &&
                   !Alias.exists?(name: previous_name, aliasable_id: id, aliasable_type: "Person") &&
          Severity: Major
          Found in app/models/people/aliases.rb - About 40 mins to fix

            Consider simplifying this complex logical expression.
            Open

                        elsif token[/\Abeg?\.?\z/i] || token[/\Abg\.?\z/i] || token[/\Abegin?\.?\z/i] || token[/\Abeginners\z/i] || token[/\Abeg:\z/i] ||
                              token[/\ABeginning\z/i]
            
                          "Beginner"
                        elsif token[/\A(exp|expt|ex|exeprt|exb|exper|exprert)\.?\z/i]
            Severity: Major
            Found in app/models/categories/name_normalization.rb - About 40 mins to fix
              Severity
              Category
              Status
              Source
              Language