expertiza/expertiza

View on GitHub
app/controllers/review_mapping_controller.rb

Summary

Maintainability
F
4 days
Test Coverage
C
70%

Class has too many lines. [469/100]
Open

class ReviewMappingController < ApplicationController
  include AuthorizationHelper

  autocomplete :user, :name
  # helper :dynamic_review_assignment

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for peer_review_strategy is too high. [95.89/15]
Open

  def peer_review_strategy(assignment_id, review_strategy, participants_hash)
    teams = review_strategy.teams
    participants = review_strategy.participants
    num_participants = participants.size

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 automatic_review_mapping is too high. [83.92/15]
Open

  def automatic_review_mapping
    assignment_id = params[:id].to_i
    assignment = Assignment.find(params[:id])
    participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
    teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!

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 peer_review_strategy has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
Open

  def peer_review_strategy(assignment_id, review_strategy, participants_hash)
    teams = review_strategy.teams
    participants = review_strategy.participants
    num_participants = participants.size

Severity: Minor
Found in app/controllers/review_mapping_controller.rb - About 1 day 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

File review_mapping_controller.rb has 471 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ReviewMappingController < ApplicationController
  include AuthorizationHelper

  autocomplete :user, :name
  # helper :dynamic_review_assignment
Severity: Minor
Found in app/controllers/review_mapping_controller.rb - About 7 hrs to fix

    Method has too many lines. [57/10]
    Open

      def peer_review_strategy(assignment_id, review_strategy, participants_hash)
        teams = review_strategy.teams
        participants = review_strategy.participants
        num_participants = participants.size
    
    

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Method has too many lines. [46/10]
    Open

      def automatic_review_mapping
        assignment_id = params[:id].to_i
        assignment = Assignment.find(params[:id])
        participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
        teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Assignment Branch Condition size for assign_reviewer_dynamically is too high. [51.63/15]
    Open

      def assign_reviewer_dynamically
        assignment = Assignment.find(params[:assignment_id])
        participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
        reviewer = participant.get_reviewer
        if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?

    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 has too many lines. [44/10]
    Open

      def assign_reviewer_dynamically
        assignment = Assignment.find(params[:assignment_id])
        participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
        reviewer = participant.get_reviewer
        if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Method assign_reviewer_dynamically has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

      def assign_reviewer_dynamically
        assignment = Assignment.find(params[:assignment_id])
        participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
        reviewer = participant.get_reviewer
        if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
    Severity: Minor
    Found in app/controllers/review_mapping_controller.rb - About 5 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 add_reviewer is too high. [44.25/15]
    Open

      def add_reviewer
        assignment = Assignment.find(params[:id])
        topic_id = params[:topic_id]
        user_id = User.where(name: params[:user][:name]).first.id
        # If instructor want to assign one student to review his/her own artifact,

    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 has too many lines. [33/10]
    Open

      def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
        if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
                            .where('created_at > :time',
                                   time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
    
    

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Assignment Branch Condition size for assign_reviewers_for_team is too high. [35.4/15]
    Open

      def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
        if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
                            .where('created_at > :time',
                                   time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
    
    

    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 add_calibration is too high. [34.47/15]
    Open

      def add_calibration
        participant = begin
                        AssignmentParticipant.where(parent_id: params[:id], user_id: session[:user].id).first
                      rescue StandardError
                        nil

    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 assign_quiz_dynamically is too high. [32.42/15]
    Open

      def assign_quiz_dynamically
        begin
          assignment = Assignment.find(params[:assignment_id])
          reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
          if ResponseMap.where(reviewed_object_id: params[:questionnaire_id], reviewer_id: params[:participant_id]).first

    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 delete_all_metareviewers is too high. [30.43/15]
    Open

      def delete_all_metareviewers
        mapping = ResponseMap.find(params[:id])
        mmappings = MetareviewResponseMap.where(reviewed_object_id: mapping.map_id)
        num_unsuccessful_deletes = 0
        mmappings.each do |mmapping|

    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 add_metareviewer is too high. [29.9/15]
    Open

      def add_metareviewer
        mapping = ResponseMap.find(params[:id])
        msg = ''
        begin
          user = User.from_params(params)

    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 has too many lines. [24/10]
    Open

      def add_reviewer
        assignment = Assignment.find(params[:id])
        topic_id = params[:topic_id]
        user_id = User.where(name: params[:user][:name]).first.id
        # If instructor want to assign one student to review his/her own artifact,

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Perceived complexity for peer_review_strategy is too high. [21/7]
    Open

      def peer_review_strategy(assignment_id, review_strategy, participants_hash)
        teams = review_strategy.teams
        participants = review_strategy.participants
        num_participants = participants.size
    
    

    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 assign_reviewer_dynamically is too high. [20/7]
    Open

      def assign_reviewer_dynamically
        assignment = Assignment.find(params[:assignment_id])
        participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
        reviewer = participant.get_reviewer
        if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?

    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

    Class ReviewMappingController has 27 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class ReviewMappingController < ApplicationController
      include AuthorizationHelper
    
      autocomplete :user, :name
      # helper :dynamic_review_assignment
    Severity: Minor
    Found in app/controllers/review_mapping_controller.rb - About 3 hrs to fix

      Assignment Branch Condition size for start_self_review is too high. [27.37/15]
      Open

        def start_self_review
          user_id = params[:reviewer_userid]
          assignment = Assignment.find(params[:assignment_id])
          team = Team.find_team_for_assignment_and_user(assignment.id, user_id).first
          begin

      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 peer_review_strategy is too high. [18/6]
      Open

        def peer_review_strategy(assignment_id, review_strategy, participants_hash)
          teams = review_strategy.teams
          participants = review_strategy.participants
          num_participants = participants.size
      
      

      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 unsubmit_review is too high. [26.7/15]
      Open

        def unsubmit_review
          @response = Response.where(map_id: params[:id]).last
          review_response_map = ReviewResponseMap.find_by(id: params[:id])
          reviewer = review_response_map.reviewer.get_reviewer.name
          reviewee = review_response_map.reviewee.name

      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 has too many lines. [20/10]
      Open

        def delete_all_metareviewers
          mapping = ResponseMap.find(params[:id])
          mmappings = MetareviewResponseMap.where(reviewed_object_id: mapping.map_id)
          num_unsuccessful_deletes = 0
          mmappings.each do |mmapping|

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Assignment Branch Condition size for delete_metareviewer is too high. [24.35/15]
      Open

        def delete_metareviewer
          mapping = MetareviewResponseMap.find(params[:id])
          assignment_id = mapping.assignment.id
          flash[:note] = 'The metareview mapping for ' + mapping.reviewee.name + ' and ' + mapping.reviewer.name + ' has been deleted.'
      
      

      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 automatic_review_mapping is too high. [15/7]
      Open

        def automatic_review_mapping
          assignment_id = params[:id].to_i
          assignment = Assignment.find(params[:id])
          participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
          teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!

      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

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

          teams.each_with_index do |team, iterator|
            selected_participants = []
            if !team.equal? teams.last
              # need to even out the # of reviews for teams
              while selected_participants.size < review_strategy.reviews_per_team

      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.

      Cyclomatic complexity for assign_reviewer_dynamically is too high. [13/6]
      Open

        def assign_reviewer_dynamically
          assignment = Assignment.find(params[:assignment_id])
          participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
          reviewer = participant.get_reviewer
          if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?

      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 delete_outstanding_reviewers is too high. [21.63/15]
      Open

        def delete_outstanding_reviewers
          assignment = Assignment.find(params[:id])
          team = AssignmentTeam.find(params[:contributor_id])
          review_response_maps = team.review_mappings
          num_remain_review_response_maps = review_response_maps.size

      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 has too many lines. [16/10]
      Open

        def add_metareviewer
          mapping = ResponseMap.find(params[:id])
          msg = ''
          begin
            user = User.from_params(params)

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Cyclomatic complexity for automatic_review_mapping is too high. [12/6]
      Open

        def automatic_review_mapping
          assignment_id = params[:id].to_i
          assignment = Assignment.find(params[:id])
          participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
          teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!

      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.

      Method has too many lines. [16/10]
      Open

        def delete_outstanding_reviewers
          assignment = Assignment.find(params[:id])
          team = AssignmentTeam.find(params[:contributor_id])
          review_response_maps = team.review_mappings
          num_remain_review_response_maps = review_response_maps.size

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Method has too many lines. [16/10]
      Open

        def assign_quiz_dynamically
          begin
            assignment = Assignment.find(params[:assignment_id])
            reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
            if ResponseMap.where(reviewed_object_id: params[:questionnaire_id], reviewer_id: params[:participant_id]).first

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Method peer_review_strategy has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def peer_review_strategy(assignment_id, review_strategy, participants_hash)
          teams = review_strategy.teams
          participants = review_strategy.participants
          num_participants = participants.size
      
      
      Severity: Major
      Found in app/controllers/review_mapping_controller.rb - About 2 hrs to fix

        Method automatic_review_mapping has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          def automatic_review_mapping
            assignment_id = params[:id].to_i
            assignment = Assignment.find(params[:id])
            participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
            teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
        Severity: Minor
        Found in app/controllers/review_mapping_controller.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 save_grade_and_comment_for_reviewer is too high. [20.9/15]
        Open

          def save_grade_and_comment_for_reviewer
            review_grade = ReviewGrade.find_or_create_by(participant_id: params[:review_grade][:participant_id])
            review_grade.attributes = review_mapping_params
            review_grade.review_graded_at = Time.now
            review_grade.reviewer_id = session[:user].id

        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 has too many lines. [15/10]
        Open

          def add_calibration
            participant = begin
                            AssignmentParticipant.where(parent_id: params[:id], user_id: session[:user].id).first
                          rescue StandardError
                            nil

        This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

        Method has too many lines. [15/10]
        Open

          def start_self_review
            user_id = params[:reviewer_userid]
            assignment = Assignment.find(params[:assignment_id])
            team = Team.find_team_for_assignment_and_user(assignment.id, user_id).first
            begin

        This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

        Assignment Branch Condition size for delete_reviewer is too high. [19.34/15]
        Open

          def delete_reviewer
            review_response_map = ReviewResponseMap.find_by(id: params[:id])
            if review_response_map && !Response.exists?(map_id: review_response_map.id)
              review_response_map.destroy
              flash[:success] = 'The review mapping for "' + review_response_map.reviewee.name + '" and "' + review_response_map.reviewer.name + '" has been deleted.'

        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 has too many lines. [14/10]
        Open

          def save_grade_and_comment_for_reviewer
            review_grade = ReviewGrade.find_or_create_by(participant_id: params[:review_grade][:participant_id])
            review_grade.attributes = review_mapping_params
            review_grade.review_graded_at = Time.now
            review_grade.reviewer_id = session[:user].id

        This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

        Assignment Branch Condition size for automatic_review_mapping_strategy is too high. [18.71/15]
        Open

          def automatic_review_mapping_strategy(assignment_id,
                                                participants, teams, student_review_num = 0,
                                                submission_review_num = 0, exclude_teams = false)
            participants_hash = {}
            participants.each { |participant| participants_hash[participant.id] = 0 }

        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 has too many lines. [12/10]
        Open

          def check_outstanding_reviews?(assignment, reviewer)
            @review_mappings = ReviewResponseMap.where(reviewer_id: reviewer.id, reviewed_object_id: assignment.id)
            @num_reviews_total = @review_mappings.size
            if @num_reviews_total.zero?
              true

        This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

        Method automatic_review_mapping has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def automatic_review_mapping
            assignment_id = params[:id].to_i
            assignment = Assignment.find(params[:id])
            participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
            teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
        Severity: Minor
        Found in app/controllers/review_mapping_controller.rb - About 1 hr to fix

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

            def automatic_review_mapping_strategy(assignment_id,
                                                  participants, teams, student_review_num = 0,
                                                  submission_review_num = 0, exclude_teams = false)
              participants_hash = {}
              participants.each { |participant| participants_hash[participant.id] = 0 }

          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 automatic_review_mapping_strategy is too high. [8/7]
          Open

            def automatic_review_mapping_strategy(assignment_id,
                                                  participants, teams, student_review_num = 0,
                                                  submission_review_num = 0, exclude_teams = false)
              participants_hash = {}
              participants.each { |participant| participants_hash[participant.id] = 0 }

          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 check_outstanding_reviews? is too high. [16.43/15]
          Open

            def check_outstanding_reviews?(assignment, reviewer)
              @review_mappings = ReviewResponseMap.where(reviewer_id: reviewer.id, reviewed_object_id: assignment.id)
              @num_reviews_total = @review_mappings.size
              if @num_reviews_total.zero?
                true

          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 assign_reviewer_dynamically has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def assign_reviewer_dynamically
              assignment = Assignment.find(params[:assignment_id])
              participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
              reviewer = participant.get_reviewer
              if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
          Severity: Minor
          Found in app/controllers/review_mapping_controller.rb - About 1 hr to fix

            Method assign_reviewers_for_team has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

              def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
                if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
                                    .where('created_at > :time',
                                           time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
            
            
            Severity: Minor
            Found in app/controllers/review_mapping_controller.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method assign_reviewers_for_team has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
                if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
                                    .where('created_at > :time',
                                           time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
            
            
            Severity: Minor
            Found in app/controllers/review_mapping_controller.rb - About 1 hr to fix

              Method automatic_review_mapping_strategy has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                def automatic_review_mapping_strategy(assignment_id,
                                                      participants, teams, student_review_num = 0,
                                                      submission_review_num = 0, exclude_teams = false)
              Severity: Minor
              Found in app/controllers/review_mapping_controller.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                      rescue StandardError
                                        nil
                Severity: Major
                Found in app/controllers/review_mapping_controller.rb - About 45 mins to fix

                  Method add_reviewer has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def add_reviewer
                      assignment = Assignment.find(params[:id])
                      topic_id = params[:topic_id]
                      user_id = User.where(name: params[:user][:name]).first.id
                      # If instructor want to assign one student to review his/her own artifact,
                  Severity: Minor
                  Found in app/controllers/review_mapping_controller.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 assign_quiz_dynamically has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def assign_quiz_dynamically
                      begin
                        assignment = Assignment.find(params[:assignment_id])
                        reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
                        if ResponseMap.where(reviewed_object_id: params[:questionnaire_id], reviewer_id: params[:participant_id]).first
                  Severity: Minor
                  Found in app/controllers/review_mapping_controller.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 check_outstanding_reviews? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def check_outstanding_reviews?(assignment, reviewer)
                      @review_mappings = ReviewResponseMap.where(reviewer_id: reviewer.id, reviewed_object_id: assignment.id)
                      @num_reviews_total = @review_mappings.size
                      if @num_reviews_total.zero?
                        true
                  Severity: Minor
                  Found in app/controllers/review_mapping_controller.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

                  Avoid parameter lists longer than 5 parameters. [6/5]
                  Open

                    def automatic_review_mapping_strategy(assignment_id,
                                                          participants, teams, student_review_num = 0,
                                                          submission_review_num = 0, exclude_teams = false)

                  This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

                  Avoid more than 3 levels of block nesting.
                  Open

                            if assignment.topics? # assignment with topics
                              topic = if params[:topic_id]
                                        SignUpTopic.find(params[:topic_id])
                                      else
                                        begin

                  This cop checks for excessive nesting of conditional and looping constructs.

                  You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                  The maximum level of nesting allowed is configurable.

                  Avoid more than 3 levels of block nesting.
                  Open

                                participants_with_min_assigned_reviews << participants.index(participant) if participants_hash[participant.id] == min_value

                  This cop checks for excessive nesting of conditional and looping constructs.

                  You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                  The maximum level of nesting allowed is configurable.

                  Avoid more than 3 levels of block nesting.
                  Open

                              rand_num = if if_condition_1 || if_condition_2
                                           # use original method to get random number
                                           rand(0..num_participants - 1)
                                         else
                                           # rand_num should be the position of this participant in original array

                  This cop checks for excessive nesting of conditional and looping constructs.

                  You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                  The maximum level of nesting allowed is configurable.

                  Use normalcase for variable numbers.
                  Open

                              if_condition_2 = ((participants_with_min_assigned_reviews.size == 1) && TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))

                  This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.

                  Example: EnforcedStyle: snake_case

                  # bad
                  
                  variable1 = 1
                  
                  # good
                  
                  variable_1 = 1

                  Example: EnforcedStyle: normalcase (default)

                  # bad
                  
                  variable_1 = 1
                  
                  # good
                  
                  variable1 = 1

                  Example: EnforcedStyle: non_integer

                  # bad
                  
                  variable1 = 1
                  
                  variable_1 = 1
                  
                  # good
                  
                  variableone = 1
                  
                  variable_one = 1

                  Use normalcase for variable numbers.
                  Open

                            if_condition_2 = (!selected_participants.include? participants[rand_num].id)

                  This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.

                  Example: EnforcedStyle: snake_case

                  # bad
                  
                  variable1 = 1
                  
                  # good
                  
                  variable_1 = 1

                  Example: EnforcedStyle: normalcase (default)

                  # bad
                  
                  variable_1 = 1
                  
                  # good
                  
                  variable1 = 1

                  Example: EnforcedStyle: non_integer

                  # bad
                  
                  variable1 = 1
                  
                  variable_1 = 1
                  
                  # good
                  
                  variableone = 1
                  
                  variable_one = 1

                  Convert if nested inside else to elsif.
                  Open

                        if review_allowed?(assignment, reviewer)

                  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

                  Replace class var @@time_create_last_review_mapping_record with a class instance var.
                  Open

                      @@time_create_last_review_mapping_record = ReviewResponseMap

                  This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

                  Use the return of the conditional for variable assignment and comparison.
                  Open

                          if assignment.auto_assign_mentor
                            team = MentoredTeam.create_team_and_node(assignment_id)
                          else
                            team = AssignmentTeam.create_team_and_node(assignment_id)
                          end

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

                        if SelfReviewResponseMap.where(reviewee_id: team.id, reviewer_id: params[:reviewer_id]).first.nil?

                  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

                  Missing top-level class documentation comment.
                  Open

                  class ReviewMappingController < ApplicationController

                  This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

                  The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

                  Example:

                  # bad
                  class Person
                    # ...
                  end
                  
                  # good
                  # Description/Explanation of Person class
                  class Person
                    # ...
                  end

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

                          if ReviewResponseMap.where(reviewee_id: params[:contributor_id], reviewer_id: reviewer.id).first.nil?

                  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

                  Missing space after #.
                  Open

                      #if exclude_teams_without_submission is true check if team has submission if not discard

                  This cop checks whether comments have a leading space after the # denoting the start of the comment. The leading space is not required for some RDoc special syntax, like #++, #--, #:nodoc, =begin- and =end comments, "shebang" directives, or rackup options.

                  Example:

                  # bad
                  #Some comment
                  
                  # good
                  # Some comment

                  Use normalcase for variable numbers.
                  Open

                              if_condition_1 = participants_with_min_assigned_reviews.empty?

                  This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.

                  Example: EnforcedStyle: snake_case

                  # bad
                  
                  variable1 = 1
                  
                  # good
                  
                  variable_1 = 1

                  Example: EnforcedStyle: normalcase (default)

                  # bad
                  
                  variable_1 = 1
                  
                  # good
                  
                  variable1 = 1

                  Example: EnforcedStyle: non_integer

                  # bad
                  
                  variable1 = 1
                  
                  variable_1 = 1
                  
                  # good
                  
                  variableone = 1
                  
                  variable_one = 1

                  Use normalcase for variable numbers.
                  Open

                            if_condition_1 = (participants_hash[participants[rand_num].id] < review_strategy.reviews_per_student)

                  This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.

                  Example: EnforcedStyle: snake_case

                  # bad
                  
                  variable1 = 1
                  
                  # good
                  
                  variable_1 = 1

                  Example: EnforcedStyle: normalcase (default)

                  # bad
                  
                  variable_1 = 1
                  
                  # good
                  
                  variable1 = 1

                  Example: EnforcedStyle: non_integer

                  # bad
                  
                  variable1 = 1
                  
                  variable_1 = 1
                  
                  # good
                  
                  variableone = 1
                  
                  variable_one = 1

                  Replace class var @@time_create_last_review_mapping_record with a class instance var.
                  Open

                    @@time_create_last_review_mapping_record = nil

                  This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

                  There are no issues that match your filters.

                  Category
                  Status