ece517-p3/expertiza

View on GitHub
app/models/assignment.rb

Summary

Maintainability
F
3 days
Test Coverage

Mass assignment is not restricted using attr_accessible
Open

class Assignment < ActiveRecord::Base
Severity: Critical
Found in app/models/assignment.rb by brakeman

This warning comes up if a model does not limit what attributes can be set through mass assignment.

In particular, this check looks for attr_accessible inside model definitions. If it is not found, this warning will be issued.

Brakeman also warns on use of attr_protected - especially since it was found to be vulnerable to bypass. Warnings for mass assignment on models using attr_protected will be reported, but at a lower confidence level.

Note that disabling mass assignment globally will suppress these warnings.

Assignment Branch Condition size for scores is too high. [131.2/15]
Open

  def scores(questions)
    scores = {}
    scores[:participants] = {}
    self.participants.each do |participant|
      scores[:participants][participant.id.to_s.to_sym] = participant.scores(questions)
Severity: Minor
Found in app/models/assignment.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

File assignment.rb has 494 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Assignment < ActiveRecord::Base
  require 'analytic/assignment_analytic'
  include AssignmentAnalytic
  include ReviewAssignment
  include QuizAssignment
Severity: Minor
Found in app/models/assignment.rb - About 7 hrs to fix

    Assignment Branch Condition size for response_map_to_metareview is too high. [64.91/15]
    Open

      def response_map_to_metareview(metareviewer)
        response_map_set = Array.new(review_mappings)
        # Reject response maps without responses
        response_map_set.reject! {|response_map| response_map.response.empty? }
        raise 'There are no reviews to metareview at this time for this assignment.' if response_map_set.empty?
    Severity: Minor
    Found in app/models/assignment.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Assignment Branch Condition size for csv_row is too high. [56.05/15]
    Open

      def self.csv_row(detail_options, answer)
        tcsv = []
        @response = Response.find(answer.response_id)
        map = ResponseMap.find(@response.map_id)
        @reviewee = Team.find_by id: map.reviewee_id
    Severity: Minor
    Found in app/models/assignment.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Class Assignment has 46 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Assignment < ActiveRecord::Base
      require 'analytic/assignment_analytic'
      include AssignmentAnalytic
      include ReviewAssignment
      include QuizAssignment
    Severity: Minor
    Found in app/models/assignment.rb - About 6 hrs to fix

      Assignment Branch Condition size for delete is too high. [40.56/15]
      Open

        def delete(force = nil)
          begin
            maps = ReviewResponseMap.where(reviewed_object_id: self.id)
            maps.each {|map| map.delete(force) }
          rescue StandardError
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Assignment Branch Condition size for export_data is too high. [35.5/15]
      Open

        def self.export_data(csv, scores, options)
          @scores = scores
          (0..@scores[:teams].length - 1).each do |index|
            team = @scores[:teams][index.to_s.to_sym]
            first_participant = team[:team].participants[0] unless team[:team].participants[0].nil?
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Assignment Branch Condition size for path is too high. [33.48/15]
      Open

        def path
          if self.course_id.nil? && self.instructor_id.nil?
            raise 'The path cannot be created. The assignment must be associated with either a course or an instructor.'
          end
          path_text = ""
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Assignment Branch Condition size for review_questionnaire_id is too high. [26.4/15]
      Open

        def review_questionnaire_id(round = nil)
          # Get the round it's in from the next duedates
          if round.nil?
            next_due_date = DueDate.get_next_due_date(self.id)
            round = next_due_date.try(:round)
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Method scores has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

        def scores(questions)
          scores = {}
          scores[:participants] = {}
          self.participants.each do |participant|
            scores[:participants][participant.id.to_s.to_sym] = participant.scores(questions)
      Severity: Minor
      Found in app/models/assignment.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

      Assignment Branch Condition size for export_details_fields is too high. [25.32/15]
      Open

        def self.export_details_fields(detail_options)
          fields = []
          fields << 'Team ID / Author ID' if detail_options['team_id'] == 'true'
          fields << 'Reviewee (Team / Student Name)' if detail_options['team_name'] == 'true'
          fields << 'Reviewer' if detail_options['reviewer'] == 'true'
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Assignment Branch Condition size for export_data_fields is too high. [23.11/15]
      Open

        def self.export_data_fields(options)
          if options['team_score'] == 'true'
            team[:scores] ?
              tcsv.push(team[:scores][:max], team[:scores][:min], team[:scores][:avg]) :
              tcsv.push('---', '---', '---')
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Assignment Branch Condition size for export is too high. [22.67/15]
      Open

        def self.export(csv, parent_id, options)
          @assignment = Assignment.find(parent_id)
          @questions = {}
          questionnaires = @assignment.questionnaires
          questionnaires.each do |questionnaire|
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Assignment Branch Condition size for export_details is too high. [21.63/15]
      Open

        def self.export_details(csv, parent_id, detail_options)
          return csv unless detail_options.value?('true')
          @assignment = Assignment.find(parent_id)
          @answers = {} # Contains all answer objects for this assignment
          # Find all unique response types
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Assignment Branch Condition size for export_individual_data_fields is too high. [20.1/15]
      Open

        def self.export_individual_data_fields(review_type, score_name)
          if pscore[review_type]
            tcsv.push(pscore[review_type][:scores][:max], pscore[review_type][:scores][:min], pscore[review_type][:scores][:avg])
          else
            tcsv.push('---', '---', '---') if options[score_name]
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Cyclomatic complexity for csv_row is too high. [10/6]
      Open

        def self.csv_row(detail_options, answer)
          tcsv = []
          @response = Response.find(answer.response_id)
          map = ResponseMap.find(@response.map_id)
          @reviewee = Team.find_by id: map.reviewee_id
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

      An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

      Cyclomatic complexity for export_details_fields is too high. [9/6]
      Open

        def self.export_details_fields(detail_options)
          fields = []
          fields << 'Team ID / Author ID' if detail_options['team_id'] == 'true'
          fields << 'Reviewee (Team / Student Name)' if detail_options['team_name'] == 'true'
          fields << 'Reviewer' if detail_options['reviewer'] == 'true'
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

      An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

      Perceived complexity for scores is too high. [10/7]
      Open

        def scores(questions)
          scores = {}
          scores[:participants] = {}
          self.participants.each do |participant|
            scores[:participants][participant.id.to_s.to_sym] = participant.scores(questions)
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

      Example:

      def my_method                   # 1
        if cond                       # 1
          case var                    # 2 (0.8 + 4 * 0.2, rounded)
          when 1 then func_one
          when 2 then func_two
          when 3 then func_three
          when 4..10 then func_other
          end
        else                          # 1
          do_something until a && b   # 2
        end                           # ===
      end                             # 7 complexity points

      Assignment Branch Condition size for valid_num_review is too high. [18.06/15]
      Open

        def valid_num_review
          self.num_reviews = self.num_reviews_allowed
          if self.num_reviews_allowed && self.num_reviews_allowed != -1 && self.num_reviews_allowed < self.num_reviews_required
            self.errors.add(:message, "Num of reviews required cannot be greater than number of reviews allowed")
          elsif self.num_metareviews_allowed && self.num_metareviews_allowed != -1 && self.num_metareviews_allowed < self.num_metareviews_required
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Perceived complexity for csv_row is too high. [10/7]
      Open

        def self.csv_row(detail_options, answer)
          tcsv = []
          @response = Response.find(answer.response_id)
          map = ResponseMap.find(@response.map_id)
          @reviewee = Team.find_by id: map.reviewee_id
      Severity: Minor
      Found in app/models/assignment.rb by rubocop

      This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

      Example:

      def my_method                   # 1
        if cond                       # 1
          case var                    # 2 (0.8 + 4 * 0.2, rounded)
          when 1 then func_one
          when 2 then func_two
          when 3 then func_three
          when 4..10 then func_other
          end
        else                          # 1
          do_something until a && b   # 2
        end                           # ===
      end                             # 7 complexity points

      Method scores has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def scores(questions)
          scores = {}
          scores[:participants] = {}
          self.participants.each do |participant|
            scores[:participants][participant.id.to_s.to_sym] = participant.scores(questions)
      Severity: Minor
      Found in app/models/assignment.rb - About 1 hr to fix

        Perceived complexity for export_details_fields is too high. [9/7]
        Open

          def self.export_details_fields(detail_options)
            fields = []
            fields << 'Team ID / Author ID' if detail_options['team_id'] == 'true'
            fields << 'Reviewee (Team / Student Name)' if detail_options['team_name'] == 'true'
            fields << 'Reviewer' if detail_options['reviewer'] == 'true'
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

        Example:

        def my_method                   # 1
          if cond                       # 1
            case var                    # 2 (0.8 + 4 * 0.2, rounded)
            when 1 then func_one
            when 2 then func_two
            when 3 then func_three
            when 4..10 then func_other
            end
          else                          # 1
            do_something until a && b   # 2
          end                           # ===
        end                             # 7 complexity points

        Cyclomatic complexity for scores is too high. [8/6]
        Open

          def scores(questions)
            scores = {}
            scores[:participants] = {}
            self.participants.each do |participant|
              scores[:participants][participant.id.to_s.to_sym] = participant.scores(questions)
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

        An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

        Cyclomatic complexity for current_stage_name is too high. [7/6]
        Open

          def current_stage_name(topic_id = nil)
            if self.staggered_deadline?
              return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))
            end
            due_date = find_current_stage(topic_id)
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

        An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

        Cyclomatic complexity for review_questionnaire_id is too high. [7/6]
        Open

          def review_questionnaire_id(round = nil)
            # Get the round it's in from the next duedates
            if round.nil?
              next_due_date = DueDate.get_next_due_date(self.id)
              round = next_due_date.try(:round)
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

        An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

        Perceived complexity for valid_num_review is too high. [8/7]
        Open

          def valid_num_review
            self.num_reviews = self.num_reviews_allowed
            if self.num_reviews_allowed && self.num_reviews_allowed != -1 && self.num_reviews_allowed < self.num_reviews_required
              self.errors.add(:message, "Num of reviews required cannot be greater than number of reviews allowed")
            elsif self.num_metareviews_allowed && self.num_metareviews_allowed != -1 && self.num_metareviews_allowed < self.num_metareviews_required
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

        Example:

        def my_method                   # 1
          if cond                       # 1
            case var                    # 2 (0.8 + 4 * 0.2, rounded)
            when 1 then func_one
            when 2 then func_two
            when 3 then func_three
            when 4..10 then func_other
            end
          else                          # 1
            do_something until a && b   # 2
          end                           # ===
        end                             # 7 complexity points

        Cyclomatic complexity for delete is too high. [7/6]
        Open

          def delete(force = nil)
            begin
              maps = ReviewResponseMap.where(reviewed_object_id: self.id)
              maps.each {|map| map.delete(force) }
            rescue StandardError
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

        An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

        Perceived complexity for delete is too high. [8/7]
        Open

          def delete(force = nil)
            begin
              maps = ReviewResponseMap.where(reviewed_object_id: self.id)
              maps.each {|map| map.delete(force) }
            rescue StandardError
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

        Example:

        def my_method                   # 1
          if cond                       # 1
            case var                    # 2 (0.8 + 4 * 0.2, rounded)
            when 1 then func_one
            when 2 then func_two
            when 3 then func_three
            when 4..10 then func_other
            end
          else                          # 1
            do_something until a && b   # 2
          end                           # ===
        end                             # 7 complexity points

        Perceived complexity for current_stage_name is too high. [8/7]
        Open

          def current_stage_name(topic_id = nil)
            if self.staggered_deadline?
              return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))
            end
            due_date = find_current_stage(topic_id)
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

        Example:

        def my_method                   # 1
          if cond                       # 1
            case var                    # 2 (0.8 + 4 * 0.2, rounded)
            when 1 then func_one
            when 2 then func_two
            when 3 then func_three
            when 4..10 then func_other
            end
          else                          # 1
            do_something until a && b   # 2
          end                           # ===
        end                             # 7 complexity points

        Cyclomatic complexity for response_map_to_metareview is too high. [7/6]
        Open

          def response_map_to_metareview(metareviewer)
            response_map_set = Array.new(review_mappings)
            # Reject response maps without responses
            response_map_set.reject! {|response_map| response_map.response.empty? }
            raise 'There are no reviews to metareview at this time for this assignment.' if response_map_set.empty?
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

        An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

        Assignment Branch Condition size for add_participant is too high. [16.4/15]
        Open

          def add_participant(user_name, can_submit, can_review, can_take_quiz)
            user = User.find_by(name: user_name)
            if user.nil?
              raise "The user account with the name #{user_name} does not exist. Please <a href='" +
                url_for(controller: 'users', action: 'new') + "'>create</a> the user first."
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

        Cyclomatic complexity for valid_num_review is too high. [7/6]
        Open

          def valid_num_review
            self.num_reviews = self.num_reviews_allowed
            if self.num_reviews_allowed && self.num_reviews_allowed != -1 && self.num_reviews_allowed < self.num_reviews_required
              self.errors.add(:message, "Num of reviews required cannot be greater than number of reviews allowed")
            elsif self.num_metareviews_allowed && self.num_metareviews_allowed != -1 && self.num_metareviews_allowed < self.num_metareviews_required
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

        An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

        Perceived complexity for review_questionnaire_id is too high. [8/7]
        Open

          def review_questionnaire_id(round = nil)
            # Get the round it's in from the next duedates
            if round.nil?
              next_due_date = DueDate.get_next_due_date(self.id)
              round = next_due_date.try(:round)
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

        Example:

        def my_method                   # 1
          if cond                       # 1
            case var                    # 2 (0.8 + 4 * 0.2, rounded)
            when 1 then func_one
            when 2 then func_two
            when 3 then func_three
            when 4..10 then func_other
            end
          else                          # 1
            do_something until a && b   # 2
          end                           # ===
        end                             # 7 complexity points

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

          def review_questionnaire_id(round = nil)
            # Get the round it's in from the next duedates
            if round.nil?
              next_due_date = DueDate.get_next_due_date(self.id)
              round = next_due_date.try(:round)
        Severity: Minor
        Found in app/models/assignment.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

        Block has too many lines. [38/25]
        Open

            self.teams.each do |team|
              scores[:teams][index.to_s.to_sym] = {}
              scores[:teams][index.to_s.to_sym][:team] = team
              if self.varying_rubrics_by_round?
                grades_by_rounds = {}
        Severity: Minor
        Found in app/models/assignment.rb by rubocop

        This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

          def delete(force = nil)
            begin
              maps = ReviewResponseMap.where(reviewed_object_id: self.id)
              maps.each {|map| map.delete(force) }
            rescue StandardError
        Severity: Minor
        Found in app/models/assignment.rb - About 1 hr to fix

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

            def self.csv_row(detail_options, answer)
              tcsv = []
              @response = Response.find(answer.response_id)
              map = ResponseMap.find(@response.map_id)
              @reviewee = Team.find_by id: map.reviewee_id
          Severity: Minor
          Found in app/models/assignment.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 response_map_to_metareview has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def response_map_to_metareview(metareviewer)
              response_map_set = Array.new(review_mappings)
              # Reject response maps without responses
              response_map_set.reject! {|response_map| response_map.response.empty? }
              raise 'There are no reviews to metareview at this time for this assignment.' if response_map_set.empty?
          Severity: Minor
          Found in app/models/assignment.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 export_details_fields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.export_details_fields(detail_options)
              fields = []
              fields << 'Team ID / Author ID' if detail_options['team_id'] == 'true'
              fields << 'Reviewee (Team / Student Name)' if detail_options['team_name'] == 'true'
              fields << 'Reviewer' if detail_options['reviewer'] == 'true'
          Severity: Minor
          Found in app/models/assignment.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 delete has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def delete(force = nil)
              begin
                maps = ReviewResponseMap.where(reviewed_object_id: self.id)
                maps.each {|map| map.delete(force) }
              rescue StandardError
          Severity: Minor
          Found in app/models/assignment.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 export has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.export(csv, parent_id, options)
              @assignment = Assignment.find(parent_id)
              @questions = {}
              questionnaires = @assignment.questionnaires
              questionnaires.each do |questionnaire|
          Severity: Minor
          Found in app/models/assignment.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 current_stage_name has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def current_stage_name(topic_id = nil)
              if self.staggered_deadline?
                return (topic_id.nil? ? 'Unknown' : get_current_stage(topic_id))
              end
              due_date = find_current_stage(topic_id)
          Severity: Minor
          Found in app/models/assignment.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 export_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.export_data(csv, scores, options)
              @scores = scores
              (0..@scores[:teams].length - 1).each do |index|
                team = @scores[:teams][index.to_s.to_sym]
                first_participant = team[:team].participants[0] unless team[:team].participants[0].nil?
          Severity: Minor
          Found in app/models/assignment.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

          Method export_details has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.export_details(csv, parent_id, detail_options)
              return csv unless detail_options.value?('true')
              @assignment = Assignment.find(parent_id)
              @answers = {} # Contains all answer objects for this assignment
              # Find all unique response types
          Severity: Minor
          Found in app/models/assignment.rb - About 25 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 link_for_current_stage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def link_for_current_stage(topic_id = nil)
              if self.staggered_deadline?
                return nil if topic_id.nil?
              end
              due_date = find_current_stage(topic_id)
          Severity: Minor
          Found in app/models/assignment.rb - About 25 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

          Specify an :inverse_of option.
          Open

            has_one :assignment_node, foreign_key: 'node_object_id', dependent: :destroy
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

          Example:

          # good
          class Blog < ApplicationRecord
            has_many :posts
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Blog < ApplicationRecord
            has_many :posts, -> { order(published_at: :desc) }
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            has_many(:posts,
              -> { order(published_at: :desc) },
              inverse_of: :blog
            )
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            with_options inverse_of: :blog do
              has_many :posts, -> { order(published_at: :desc) }
            end
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          # good
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end

          Example:

          # bad
          # However, RuboCop can not detect this pattern...
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician
            belongs_to :patient
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end
          
          # good
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician, inverse_of: :appointments
            belongs_to :patient, inverse_of: :appointments
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end

          @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

          Specify an :inverse_of option.
          Open

            belongs_to :instructor, class_name: 'User'
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

          Example:

          # good
          class Blog < ApplicationRecord
            has_many :posts
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Blog < ApplicationRecord
            has_many :posts, -> { order(published_at: :desc) }
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            has_many(:posts,
              -> { order(published_at: :desc) },
              inverse_of: :blog
            )
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            with_options inverse_of: :blog do
              has_many :posts, -> { order(published_at: :desc) }
            end
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          # good
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end

          Example:

          # bad
          # However, RuboCop can not detect this pattern...
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician
            belongs_to :patient
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end
          
          # good
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician, inverse_of: :appointments
            belongs_to :patient, inverse_of: :appointments
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end

          @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

          Specify an :inverse_of option.
          Open

            has_many :teams, class_name: 'AssignmentTeam', foreign_key: 'parent_id', dependent: :destroy
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

          Example:

          # good
          class Blog < ApplicationRecord
            has_many :posts
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Blog < ApplicationRecord
            has_many :posts, -> { order(published_at: :desc) }
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            has_many(:posts,
              -> { order(published_at: :desc) },
              inverse_of: :blog
            )
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            with_options inverse_of: :blog do
              has_many :posts, -> { order(published_at: :desc) }
            end
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          # good
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end

          Example:

          # bad
          # However, RuboCop can not detect this pattern...
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician
            belongs_to :patient
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end
          
          # good
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician, inverse_of: :appointments
            belongs_to :patient, inverse_of: :appointments
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end

          @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

          Specify an :inverse_of option.
          Open

            has_many :invitations, class_name: 'Invitation', foreign_key: 'assignment_id', dependent: :destroy
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

          Example:

          # good
          class Blog < ApplicationRecord
            has_many :posts
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Blog < ApplicationRecord
            has_many :posts, -> { order(published_at: :desc) }
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            has_many(:posts,
              -> { order(published_at: :desc) },
              inverse_of: :blog
            )
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            with_options inverse_of: :blog do
              has_many :posts, -> { order(published_at: :desc) }
            end
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          # good
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end

          Example:

          # bad
          # However, RuboCop can not detect this pattern...
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician
            belongs_to :patient
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end
          
          # good
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician, inverse_of: :appointments
            belongs_to :patient, inverse_of: :appointments
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end

          @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

          Specify an :inverse_of option.
          Open

            has_many :sign_up_topics, foreign_key: 'assignment_id', dependent: :destroy
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

          Example:

          # good
          class Blog < ApplicationRecord
            has_many :posts
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Blog < ApplicationRecord
            has_many :posts, -> { order(published_at: :desc) }
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            has_many(:posts,
              -> { order(published_at: :desc) },
              inverse_of: :blog
            )
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            with_options inverse_of: :blog do
              has_many :posts, -> { order(published_at: :desc) }
            end
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          # good
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end

          Example:

          # bad
          # However, RuboCop can not detect this pattern...
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician
            belongs_to :patient
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end
          
          # good
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician, inverse_of: :appointments
            belongs_to :patient, inverse_of: :appointments
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end

          @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

          Specify an :inverse_of option.
          Open

            has_many :response_maps, foreign_key: 'reviewed_object_id', dependent: :destroy
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

          Example:

          # good
          class Blog < ApplicationRecord
            has_many :posts
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Blog < ApplicationRecord
            has_many :posts, -> { order(published_at: :desc) }
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            has_many(:posts,
              -> { order(published_at: :desc) },
              inverse_of: :blog
            )
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            with_options inverse_of: :blog do
              has_many :posts, -> { order(published_at: :desc) }
            end
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          # good
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end

          Example:

          # bad
          # However, RuboCop can not detect this pattern...
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician
            belongs_to :patient
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end
          
          # good
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician, inverse_of: :appointments
            belongs_to :patient, inverse_of: :appointments
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end

          @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

          Specify an :inverse_of option.
          Open

            has_many :due_dates, class_name: 'AssignmentDueDate', foreign_key: 'parent_id', dependent: :destroy
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

          Example:

          # good
          class Blog < ApplicationRecord
            has_many :posts
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Blog < ApplicationRecord
            has_many :posts, -> { order(published_at: :desc) }
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            has_many(:posts,
              -> { order(published_at: :desc) },
              inverse_of: :blog
            )
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            with_options inverse_of: :blog do
              has_many :posts, -> { order(published_at: :desc) }
            end
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          # good
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end

          Example:

          # bad
          # However, RuboCop can not detect this pattern...
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician
            belongs_to :patient
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end
          
          # good
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician, inverse_of: :appointments
            belongs_to :patient, inverse_of: :appointments
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end

          @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

          Specify an :inverse_of option.
          Open

            has_many :participants, class_name: 'AssignmentParticipant', foreign_key: 'parent_id', dependent: :destroy
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

          Example:

          # good
          class Blog < ApplicationRecord
            has_many :posts
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Blog < ApplicationRecord
            has_many :posts, -> { order(published_at: :desc) }
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            has_many(:posts,
              -> { order(published_at: :desc) },
              inverse_of: :blog
            )
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            with_options inverse_of: :blog do
              has_many :posts, -> { order(published_at: :desc) }
            end
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          # good
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end

          Example:

          # bad
          # However, RuboCop can not detect this pattern...
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician
            belongs_to :patient
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end
          
          # good
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician, inverse_of: :appointments
            belongs_to :patient, inverse_of: :appointments
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end

          @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

          Specify an :inverse_of option.
          Open

            has_many :review_mappings, class_name: 'ReviewResponseMap', foreign_key: 'reviewed_object_id', dependent: :destroy
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

          Example:

          # good
          class Blog < ApplicationRecord
            has_many :posts
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Blog < ApplicationRecord
            has_many :posts, -> { order(published_at: :desc) }
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            has_many(:posts,
              -> { order(published_at: :desc) },
              inverse_of: :blog
            )
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end
          
          # good
          class Blog < ApplicationRecord
            with_options inverse_of: :blog do
              has_many :posts, -> { order(published_at: :desc) }
            end
          end
          
          class Post < ApplicationRecord
            belongs_to :blog
          end

          Example:

          # bad
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable
          end
          
          # good
          class Picture < ApplicationRecord
            belongs_to :imageable, polymorphic: true
          end
          
          class Employee < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end
          
          class Product < ApplicationRecord
            has_many :pictures, as: :imageable, inverse_of: :imageable
          end

          Example:

          # bad
          # However, RuboCop can not detect this pattern...
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician
            belongs_to :patient
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end
          
          # good
          class Physician < ApplicationRecord
            has_many :appointments
            has_many :patients, through: :appointments
          end
          
          class Appointment < ApplicationRecord
            belongs_to :physician, inverse_of: :appointments
            belongs_to :patient, inverse_of: :appointments
          end
          
          class Patient < ApplicationRecord
            has_many :appointments
            has_many :physicians, through: :appointments
          end

          @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

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

                    if !grades_by_rounds[round_sym][:max].nil? && scores[:teams][index.to_s.to_sym][:scores][:max] < grades_by_rounds[round_sym][:max]
                      scores[:teams][index.to_s.to_sym][:scores][:max] = grades_by_rounds[round_sym][:max]
                    end
          Severity: Minor
          Found in app/models/assignment.rb and 1 other location - About 50 mins to fix
          app/models/assignment.rb on lines 184..186

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

          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

                    if !grades_by_rounds[round_sym][:min].nil? && scores[:teams][index.to_s.to_sym][:scores][:min] > grades_by_rounds[round_sym][:min]
                      scores[:teams][index.to_s.to_sym][:scores][:min] = grades_by_rounds[round_sym][:min]
                    end
          Severity: Minor
          Found in app/models/assignment.rb and 1 other location - About 50 mins to fix
          app/models/assignment.rb on lines 181..183

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

          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

              begin
                maps = ReviewResponseMap.where(reviewed_object_id: self.id)
                maps.each {|map| map.delete(force) }
              rescue StandardError
                raise "There is at least one review response that exists for #{self.name}."
          Severity: Minor
          Found in app/models/assignment.rb and 1 other location - About 15 mins to fix
          app/models/assignment.rb on lines 258..262

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

          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

              begin
                maps = TeammateReviewResponseMap.where(reviewed_object_id: self.id)
                maps.each {|map| map.delete(force) }
              rescue StandardError
                raise "There is at least one teammate review response that exists for #{self.name}."
          Severity: Minor
          Found in app/models/assignment.rb and 1 other location - About 15 mins to fix
          app/models/assignment.rb on lines 251..255

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

          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

          Use a guard clause instead of wrapping the code inside a conditional expression.
          Open

                if directory.size == 2
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          Use a guard clause instead of wrapping the code inside a conditional expression

          Example:

          # bad
          def test
            if something
              work
            end
          end
          
          # good
          def test
            return unless something
            work
          end
          
          # also good
          def test
            work if something
          end
          
          # bad
          if something
            raise 'exception'
          else
            ok
          end
          
          # good
          raise 'exception' if something
          ok

          Convert if nested inside else to elsif.
          Open

                tcsv.push('---', '---', '---') if options[score_name]
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          If the else branch of a conditional consists solely of an if node, it can be combined with the else to become an elsif. This helps to keep the nesting level from getting too deep.

          Example:

          # bad
          if condition_a
            action_a
          else
            if condition_b
              action_b
            else
              action_c
            end
          end
          
          # good
          if condition_a
            action_a
          elsif condition_b
            action_b
          else
            action_c
          end

          Useless assignment to variable - path_text.
          Open

              path_text = ""
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

          assigned but unused variable - foo

          Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

          Example:

          # bad
          
          def some_method
            some_var = 1
            do_something
          end

          Example:

          # good
          
          def some_method
            some_var = 1
            do_something(some_var)
          end

          Rename has_badge? to badge?.
          Open

            def has_badge?
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop makes sure that predicates are named properly.

          Example:

          # bad
          def is_even?(value)
          end
          
          # good
          def even?(value)
          end
          
          # bad
          def has_value?
          end
          
          # good
          def value?
          end

          Do not prefix writer method names with set_.
          Open

            def self.set_courses_to_assignment(user)
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop makes sure that accessor methods are named properly.

          Example:

          # bad
          def set_attribute(value)
          end
          
          # good
          def attribute=(value)
          end
          
          # bad
          def get_attribute
          end
          
          # good
          def attribute
          end

          Use a guard clause instead of wrapping the code inside a conditional expression.
          Open

                if due_date != 'Finished' && !due_date.nil? && !due_date.deadline_name.nil?
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          Use a guard clause instead of wrapping the code inside a conditional expression

          Example:

          # bad
          def test
            if something
              work
            end
          end
          
          # good
          def test
            return unless something
            work
          end
          
          # also good
          def test
            work if something
          end
          
          # bad
          if something
            raise 'exception'
          else
            ok
          end
          
          # good
          raise 'exception' if something
          ok

          Use a guard clause instead of wrapping the code inside a conditional expression.
          Open

              unless self.staggered_deadline?
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          Use a guard clause instead of wrapping the code inside a conditional expression

          Example:

          # bad
          def test
            if something
              work
            end
          end
          
          # good
          def test
            return unless something
            work
          end
          
          # also good
          def test
            work if something
          end
          
          # bad
          if something
            raise 'exception'
          else
            ok
          end
          
          # good
          raise 'exception' if something
          ok

          Use a guard clause instead of wrapping the code inside a conditional expression.
          Open

              if due_date.nil? or due_date == 'Finished' or due_date.is_a?(TopicDueDate)
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          Use a guard clause instead of wrapping the code inside a conditional expression

          Example:

          # bad
          def test
            if something
              work
            end
          end
          
          # good
          def test
            return unless something
            work
          end
          
          # also good
          def test
            work if something
          end
          
          # bad
          if something
            raise 'exception'
          else
            ok
          end
          
          # good
          raise 'exception' if something
          ok

          Avoid multi-line ternary operators, use if or unless instead.
          Open

                team[:scores] ?
                  tcsv.push(team[:scores][:max], team[:scores][:min], team[:scores][:avg]) :
                  tcsv.push('---', '---', '---')
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop checks for multi-line ternary op expressions.

          Example:

          # bad
          a = cond ?
            b : c
          a = cond ? b :
              c
          a = cond ?
              b :
              c
          
          # good
          a = cond ? b : c
          a =
            if cond
              b
            else
              c
            end

          Useless assignment to variable - pscore.
          Open

                pscore = @scores[:participants][first_participant.id.to_s.to_sym]
          Severity: Minor
          Found in app/models/assignment.rb by rubocop

          This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

          assigned but unused variable - foo

          Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

          Example:

          # bad
          
          def some_method
            some_var = 1
            do_something
          end

          Example:

          # good
          
          def some_method
            some_var = 1
            do_something(some_var)
          end

          There are no issues that match your filters.

          Category
          Status