scottwillson/racing_on_rails

View on GitHub

Showing 333 of 1,278 total issues

Method to_excel has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def to_excel(value)
    case value
    when TrueClass
      "1"
    when FalseClass
Severity: Minor
Found in app/helpers/application_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 _stable_merge has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def _stable_merge(left, right, &predicate)
    sorted = []
    until left.empty? || right.empty?
      sorted << if predicate
                  if yield(right.first, left.first)
Severity: Minor
Found in lib/enumerable/stable_sort.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 test_compare_by_most_recent_result has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def test_compare_by_most_recent_result
        x = Struct::CalculatorResult.new
        y = Struct::CalculatorResult.new
        assert_equal 0, Calculator.compare_by_most_recent_result(x, y)

Severity: Minor
Found in test_ruby/models/competitions/calculations/place_test.rb - About 1 hr to fix

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

        def category_names
          [
            "Category 3 Men",
            "Category 3 Women",
            "Category 4/5 Men",
    Severity: Minor
    Found in app/models/competitions/oregon_tt_cup.rb - About 1 hr to fix

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

          def merge(team)
            raise(ArgumentError, "Cannot merge nil team") unless team
            return false if team == self
      
            Team.transaction do
      Severity: Minor
      Found in app/models/teams/merge.rb - About 1 hr to fix

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

                def test_by_time
                  category = Models::Category.new("Masters Men")
                  rules = Rules.new(category_rules: [Models::CategoryRule.new(category)], place_by: "time")
                  calculator = Calculator.new(rules: rules, source_results: [])
                  event_category = calculator.event_categories.first
        Severity: Minor
        Found in test_ruby/models/calculations/v3/steps/place_test.rb - About 1 hr to fix

          Method calculate! has 27 lines of code (exceeds 25 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/bar.rb - About 1 hr to fix

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

              def index
                @calendar_tab = "Calendar"
            
                respond_to do |format|
                  format.html do
            Severity: Minor
            Found in app/controllers/schedule_controller.rb - About 1 hr to fix

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

                def calculate!(source_calculations: true)
                  ActiveSupport::Notifications.instrument "calculate.calculations.#{name}.racing_on_rails" do
                    clear_cache
                    clear_source_results_cache
                    calculate_source_calculations if source_calculations
              Severity: Minor
              Found in app/models/calculations/v3/calculation.rb - About 1 hr to fix

                Method unique_number has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def unique_number
                    _discipline = Discipline.find(discipline_id)
                    if number_issuer.association? && RaceNumber.rental?(value, _discipline)
                      errors.add("value", "#{value} is a rental number. #{RacingAssociation.current.short_name} rental numbers: #{RacingAssociation.current.rental_numbers}")
                      person.errors.add("value", "#{value} is a rental number. #{RacingAssociation.current.short_name} rental numbers: #{RacingAssociation.current.rental_numbers}")
                Severity: Minor
                Found in app/models/race_number.rb - About 1 hr to fix

                  Method test_junior has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def test_junior
                        category = Stub.new
                        assert !category.junior?, "No ages junior?"
                  
                        category = Stub.new
                  Severity: Minor
                  Found in test_ruby/models/categories/ages_test.rb - About 1 hr to fix

                    Method test_minimum_events_before_event_complete has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                          def test_minimum_events_before_event_complete
                            source_results = [
                              result(id: 1, event_id: 1, race_id: 1, participant_id: 1, place: "1"),
                              result(id: 2, event_id: 2, race_id: 2, participant_id: 1, place: "6"),
                              result(id: 3, event_id: 2, race_id: 2, participant_id: 2, place: "2"),
                    Severity: Minor
                    Found in test_ruby/models/competitions/calculations/select_results_test.rb - About 1 hr to fix

                      Method test_weekly_series_calculated_overall has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                              def test_weekly_series_calculated_overall
                                category = Models::Category.new("Women")
                                rules = Rules.new(
                                  category_rules: [Models::CategoryRule.new(category)],
                                  weekday_events: false

                        Method import has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                              def import
                                case params[:commit]
                                when "Cancel"
                                  session[:people_file_path] = nil
                                  redirect_to(action: "index")
                        Severity: Minor
                        Found in app/controllers/admin/people/import.rb - About 1 hr to fix

                          Method update has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              def update
                                @category = Category.find(params[:id])
                                @category.assign_attributes category_params
                          
                                if @category.name_changed?
                          Severity: Minor
                          Found in app/controllers/admin/categories_controller.rb - About 1 hr to fix

                            Consider simplifying this complex logical expression.
                            Open

                                  if candidate_categories.one? { |category| category.ability_begin == highest_ability && category.gender == gender && (!category.junior? || category.ages.size <= ages.size) }
                                    highest_ability_category = candidate_categories.detect { |category| category.ability_begin == highest_ability && category.gender == gender && (!category.junior? || category.ages.size <= ages.size) }
                                    debug "highest ability for gender: #{highest_ability_category.name}"
                                    return highest_ability_category if highest_ability_category.include?(self)
                                  end
                            Severity: Major
                            Found in app/models/categories/matching.rb - About 1 hr to fix

                              Consider simplifying this complex logical expression.
                              Open

                                  unless administrator? ||
                                         (@event && (current_person == @event.promoter || @event.editors.include?(current_person))) ||
                                         (@race && (current_person == @race.event.promoter || @race.event.editors.include?(current_person)))
                              
                                    redirect_to unauthorized_path
                              Severity: Major
                              Found in app/controllers/authorization.rb - About 1 hr to fix

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

                                  def unique_number
                                    _discipline = Discipline.find(discipline_id)
                                    if number_issuer.association? && RaceNumber.rental?(value, _discipline)
                                      errors.add("value", "#{value} is a rental number. #{RacingAssociation.current.short_name} rental numbers: #{RacingAssociation.current.rental_numbers}")
                                      person.errors.add("value", "#{value} is a rental number. #{RacingAssociation.current.short_name} rental numbers: #{RacingAssociation.current.rental_numbers}")
                                Severity: Minor
                                Found in app/models/race_number.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 destroy has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                Open

                                  def self.destroy(post)
                                    transaction do
                                      original = find_original(post)
                                      if original
                                        original.replies_count = original.replies_count - 1
                                Severity: Minor
                                Found in app/models/post.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 valid_dates has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    def valid_dates
                                      if all_year?
                                        errors.add "start_date", "must be January 1st, but was: '#{start_date}'" if start_date.nil? || start_date != start_date.beginning_of_year
                                        errors.add "end_date", "must be December 31st, but was: '#{end_date}'" if end_date.nil? || end_date != end_date.end_of_year
                                      end
                                Severity: Minor
                                Found in app/models/competitions/dates.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

                                Severity
                                Category
                                Status
                                Source
                                Language