app/models/competitions/competition.rb
File competition.rb
has 496 lines of code (exceeds 250 allowed). Consider refactoring. Open
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.
#
Class Competition
has 55 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class Competition < Event
include Competitions::Categories
include Competitions::Dates
include Competitions::Naming
include Competitions::Points
Method source_results_query
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def source_results_query(race)
query = Result
.select(
"distinct results.id as id",
"1 as multiplier",
Method add_upgrade_results
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
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
Method calculate!
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
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)
- Read upRead up
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
Open
# TODO: Why do we need explicit dirty check?
- Exclude checks
TODO found Open
Open
# TODO: ensure subclasses call super
- Exclude checks
TODO found Open
Open
# TODO: just do this in source_results with join
- Exclude checks