scottwillson/racing_on_rails

View on GitHub
app/models/competitions/competition.rb

Summary

Maintainability
D
2 days
Test Coverage

File competition.rb has 496 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Competitions
  # Results that derive their results from other Events. Se TYPES.
  # Year-long: BAR, Ironman, WSBA Rider Rankings, Oregon Cup.
  # Event-based: Cross Crusade, Mount Tabor Series.
  #
Severity: Minor
Found in app/models/competitions/competition.rb - About 7 hrs to fix

    Class Competition has 55 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Competition < Event
        include Competitions::Categories
        include Competitions::Dates
        include Competitions::Naming
        include Competitions::Points
    Severity: Major
    Found in app/models/competitions/competition.rb - About 7 hrs to fix

      Method source_results_query has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def source_results_query(race)
            query = Result
                    .select(
                      "distinct results.id as id",
                      "1 as multiplier",
      Severity: Minor
      Found in app/models/competitions/competition.rb - About 2 hrs to fix

        Method add_upgrade_results has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def add_upgrade_results(results, race)
              if race.name.in?(upgrades.keys)
                upgrade_categories = Array.wrap(upgrades[race.name])
                upgrade_races = races.select { |r| r.name.in?(upgrade_categories) }
                results.to_a + Result.connection.select_all(Result
        Severity: Minor
        Found in app/models/competitions/competition.rb - About 1 hr to fix

          Method calculate! has a Cognitive Complexity of 7 (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)
                    competition = find_or_create_for_year(year)
          Severity: Minor
          Found in app/models/competitions/competition.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

          TODO found
          Open

                # TODO: Why do we need explicit dirty check?

          TODO found
          Open

                # TODO: ensure subclasses call super

          TODO found
          Open

              # TODO: just do this in source_results with join

          There are no issues that match your filters.

          Category
          Status