expertiza/expertiza

View on GitHub
app/models/assignment_form.rb

Summary

Maintainability
F
4 days
Test Coverage
C
76%

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

class AssignmentForm
  attr_accessor :assignment,
                :assignment_questionnaires,
                :due_dates,
                :tag_prompt_deployments,
Severity: Minor
Found in app/models/assignment_form.rb by rubocop

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

  def assignment_questionnaire(questionnaire_type, round_number, topic_id, duty_id = nil)
    round_number = nil if round_number.blank?
    topic_id = nil if topic_id.blank?

    # Default value of duty_id is nil, and when duty_id is not nil, then it means that the function call
Severity: Minor
Found in app/models/assignment_form.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 has too many lines. [45/10]
Open

  def assignment_questionnaire(questionnaire_type, round_number, topic_id, duty_id = nil)
    round_number = nil if round_number.blank?
    topic_id = nil if topic_id.blank?

    # Default value of duty_id is nil, and when duty_id is not nil, then it means that the function call
Severity: Minor
Found in app/models/assignment_form.rb by rubocop

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.

File assignment_form.rb has 373 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'active_support/time_with_zone'

class AssignmentForm
  attr_accessor :assignment,
                :assignment_questionnaires,
Severity: Minor
Found in app/models/assignment_form.rb - About 4 hrs to fix

    Method update_tag_prompt_deployments has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

      def update_tag_prompt_deployments(attributes)
        unless attributes.nil?
          attributes.each do |key, value|
            if @assignment.vary_by_topic?
              @assignment.questionnaires.uniq.each do |questionnaire|
    Severity: Minor
    Found in app/models/assignment_form.rb - About 4 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

    Class AssignmentForm has 33 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class AssignmentForm
      attr_accessor :assignment,
                    :assignment_questionnaires,
                    :due_dates,
                    :tag_prompt_deployments,
    Severity: Minor
    Found in app/models/assignment_form.rb - About 4 hrs to fix

      Method update_assignment_questionnaires has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

        def update_assignment_questionnaires(attributes)
          return if attributes.nil? || attributes.empty?
      
          if attributes[0].key?(:questionnaire_weight)
            validate_assignment_questionnaires_weights(attributes)
      Severity: Minor
      Found in app/models/assignment_form.rb - About 4 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 update_due_dates is too high. [33.32/15]
      Open

        def update_due_dates(attributes, user)
          return false unless attributes
      
          attributes.each do |due_date|
            next if due_date[:due_at].blank?
      Severity: Minor
      Found in app/models/assignment_form.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 copy is too high. [32.08/15]
      Open

        def self.copy(assignment_id, user)
          Assignment.record_timestamps = false
          old_assign = Assignment.find(assignment_id)
          new_assign = old_assign.dup
          user.set_instructor(new_assign)
      Severity: Minor
      Found in app/models/assignment_form.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 assignment_questionnaire has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        def assignment_questionnaire(questionnaire_type, round_number, topic_id, duty_id = nil)
          round_number = nil if round_number.blank?
          topic_id = nil if topic_id.blank?
      
          # Default value of duty_id is nil, and when duty_id is not nil, then it means that the function call
      Severity: Minor
      Found in app/models/assignment_form.rb - About 3 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

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

        def update_assignment_questionnaires(attributes)
          return if attributes.nil? || attributes.empty?
      
          if attributes[0].key?(:questionnaire_weight)
            validate_assignment_questionnaires_weights(attributes)
      Severity: Minor
      Found in app/models/assignment_form.rb by rubocop

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

        def update_assignment_questionnaires(attributes)
          return if attributes.nil? || attributes.empty?
      
          if attributes[0].key?(:questionnaire_weight)
            validate_assignment_questionnaires_weights(attributes)
      Severity: Minor
      Found in app/models/assignment_form.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 update is too high. [30.63/15]
      Open

        def update(attributes, user, _vary_by_topic_desired = false)
          @has_errors = false
          has_late_policy = false
          if attributes[:assignment][:late_policy_id].to_i > 0
            has_late_policy = true
      Severity: Minor
      Found in app/models/assignment_form.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 assignment_questionnaire is too high. [22/7]
      Open

        def assignment_questionnaire(questionnaire_type, round_number, topic_id, duty_id = nil)
          round_number = nil if round_number.blank?
          topic_id = nil if topic_id.blank?
      
          # Default value of duty_id is nil, and when duty_id is not nil, then it means that the function call
      Severity: Minor
      Found in app/models/assignment_form.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 assignment_questionnaire is too high. [20/6]
      Open

        def assignment_questionnaire(questionnaire_type, round_number, topic_id, duty_id = nil)
          round_number = nil if round_number.blank?
          topic_id = nil if topic_id.blank?
      
          # Default value of duty_id is nil, and when duty_id is not nil, then it means that the function call
      Severity: Minor
      Found in app/models/assignment_form.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.

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

        def self.copy(assignment_id, user)
          Assignment.record_timestamps = false
          old_assign = Assignment.find(assignment_id)
          new_assign = old_assign.dup
          user.set_instructor(new_assign)
      Severity: Minor
      Found in app/models/assignment_form.rb by rubocop

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

        def create_or_update_tag_prompt_deployments(questionnaire_id, value)
          (0..value['tag_prompt'].count - 1).each do |i|
            tag_dep = nil
            tag_params = {
                  assignment_id: @assignment.id,
      Severity: Minor
      Found in app/models/assignment_form.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 has too many lines. [21/10]
      Open

        def update_due_dates(attributes, user)
          return false unless attributes
      
          attributes.each do |due_date|
            next if due_date[:due_at].blank?
      Severity: Minor
      Found in app/models/assignment_form.rb by rubocop

      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. [19/10]
      Open

        def update(attributes, user, _vary_by_topic_desired = false)
          @has_errors = false
          has_late_policy = false
          if attributes[:assignment][:late_policy_id].to_i > 0
            has_late_policy = true
      Severity: Minor
      Found in app/models/assignment_form.rb by rubocop

      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. [18/10]
      Open

        def create_or_update_tag_prompt_deployments(questionnaire_id, value)
          (0..value['tag_prompt'].count - 1).each do |i|
            tag_dep = nil
            tag_params = {
                  assignment_id: @assignment.id,
      Severity: Minor
      Found in app/models/assignment_form.rb by rubocop

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

        def update_tag_prompt_deployments(attributes)
          unless attributes.nil?
            attributes.each do |key, value|
              if @assignment.vary_by_topic?
                @assignment.questionnaires.uniq.each do |questionnaire|
      Severity: Minor
      Found in app/models/assignment_form.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 update_due_dates has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

        def update_due_dates(attributes, user)
          return false unless attributes
      
          attributes.each do |due_date|
            next if due_date[:due_at].blank?
      Severity: Minor
      Found in app/models/assignment_form.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

      Cyclomatic complexity for update_assignment_questionnaires is too high. [11/6]
      Open

        def update_assignment_questionnaires(attributes)
          return if attributes.nil? || attributes.empty?
      
          if attributes[0].key?(:questionnaire_weight)
            validate_assignment_questionnaires_weights(attributes)
      Severity: Minor
      Found in app/models/assignment_form.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.

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

        def update_tag_prompt_deployments(attributes)
          unless attributes.nil?
            attributes.each do |key, value|
              if @assignment.vary_by_topic?
                @assignment.questionnaires.uniq.each do |questionnaire|
      Severity: Minor
      Found in app/models/assignment_form.rb by rubocop

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

        def update_assignment_questionnaires(attributes)
          return if attributes.nil? || attributes.empty?
      
          if attributes[0].key?(:questionnaire_weight)
            validate_assignment_questionnaires_weights(attributes)
      Severity: Minor
      Found in app/models/assignment_form.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 update is too high. [10/6]
      Open

        def update(attributes, user, _vary_by_topic_desired = false)
          @has_errors = false
          has_late_policy = false
          if attributes[:assignment][:late_policy_id].to_i > 0
            has_late_policy = true
      Severity: Minor
      Found in app/models/assignment_form.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 update is too high. [11/7]
      Open

        def update(attributes, user, _vary_by_topic_desired = false)
          @has_errors = false
          has_late_policy = false
          if attributes[:assignment][:late_policy_id].to_i > 0
            has_late_policy = true
      Severity: Minor
      Found in app/models/assignment_form.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 has too many lines. [13/10]
      Open

        def rubric_weight_error(attributes)
          error = false
          attributes[:assignment_questionnaire].each do |assignment_questionnaire|
            # Check rubrics to make sure weight is 0 if there are no Scored Questions
            scored_questionnaire = false
      Severity: Minor
      Found in app/models/assignment_form.rb by rubocop

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

        def update_tag_prompt_deployments(attributes)
          unless attributes.nil?
            attributes.each do |key, value|
              if @assignment.vary_by_topic?
                @assignment.questionnaires.uniq.each do |questionnaire|
      Severity: Minor
      Found in app/models/assignment_form.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 update_due_dates is too high. [8/6]
      Open

        def update_due_dates(attributes, user)
          return false unless attributes
      
          attributes.each do |due_date|
            next if due_date[:due_at].blank?
      Severity: Minor
      Found in app/models/assignment_form.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.

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

        def self.copy_assignment_questionnaire(old_assign, new_assign, user)
          old_assign.assignment_questionnaires.each do |aq|
            AssignmentQuestionnaire.create(
              assignment_id: new_assign.id,
              questionnaire_id: aq.questionnaire_id,
      Severity: Minor
      Found in app/models/assignment_form.rb by rubocop

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

        def update_tag_prompt_deployments(attributes)
          unless attributes.nil?
            attributes.each do |key, value|
              if @assignment.vary_by_topic?
                @assignment.questionnaires.uniq.each do |questionnaire|
      Severity: Minor
      Found in app/models/assignment_form.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 update_due_dates is too high. [9/7]
      Open

        def update_due_dates(attributes, user)
          return false unless attributes
      
          attributes.each do |due_date|
            next if due_date[:due_at].blank?
      Severity: Minor
      Found in app/models/assignment_form.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 assignment_questionnaire has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def assignment_questionnaire(questionnaire_type, round_number, topic_id, duty_id = nil)
          round_number = nil if round_number.blank?
          topic_id = nil if topic_id.blank?
      
          # Default value of duty_id is nil, and when duty_id is not nil, then it means that the function call
      Severity: Minor
      Found in app/models/assignment_form.rb - About 1 hr to fix

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

          def add_to_delayed_queue
            duedates = AssignmentDueDate.where(parent_id: @assignment.id)
            duedates.each do |due_date|
              deadline_type = DeadlineType.find(due_date.deadline_type_id).name
              diff_btw_time_left_and_threshold, min_left = get_time_diff_btw_due_date_and_now(due_date)
        Severity: Minor
        Found in app/models/assignment_form.rb by rubocop

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

          def initialize(args = {})
            @assignment = Assignment.new(args[:assignment])
            if args[:assignment].nil?
              @assignment.course = Course.find(args[:parent_id]) if args[:parent_id]
              @assignment.instructor = @assignment.course.instructor if @assignment.course
        Severity: Minor
        Found in app/models/assignment_form.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 add_to_delayed_queue is too high. [16.64/15]
        Open

          def add_to_delayed_queue
            duedates = AssignmentDueDate.where(parent_id: @assignment.id)
            duedates.each do |due_date|
              deadline_type = DeadlineType.find(due_date.deadline_type_id).name
              diff_btw_time_left_and_threshold, min_left = get_time_diff_btw_due_date_and_now(due_date)
        Severity: Minor
        Found in app/models/assignment_form.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 update has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def update(attributes, user, _vary_by_topic_desired = false)
            @has_errors = false
            has_late_policy = false
            if attributes[:assignment][:late_policy_id].to_i > 0
              has_late_policy = true
        Severity: Minor
        Found in app/models/assignment_form.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 add_to_delayed_queue has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def add_to_delayed_queue
            duedates = AssignmentDueDate.where(parent_id: @assignment.id)
            duedates.each do |due_date|
              deadline_type = DeadlineType.find(due_date.deadline_type_id).name
              diff_btw_time_left_and_threshold, min_left = get_time_diff_btw_due_date_and_now(due_date)
        Severity: Minor
        Found in app/models/assignment_form.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 update_assignment_questionnaires has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def update_assignment_questionnaires(attributes)
            return if attributes.nil? || attributes.empty?
        
            if attributes[0].key?(:questionnaire_weight)
              validate_assignment_questionnaires_weights(attributes)
        Severity: Minor
        Found in app/models/assignment_form.rb - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                  return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
          Severity: Major
          Found in app/models/assignment_form.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                    return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
            Severity: Major
            Found in app/models/assignment_form.rb - About 45 mins to fix

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

                def rubric_weight_error(attributes)
                  error = false
                  attributes[:assignment_questionnaire].each do |assignment_questionnaire|
                    # Check rubrics to make sure weight is 0 if there are no Scored Questions
                    scored_questionnaire = false
              Severity: Minor
              Found in app/models/assignment_form.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 create_or_update_tag_prompt_deployments has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def create_or_update_tag_prompt_deployments(questionnaire_id, value)
                  (0..value['tag_prompt'].count - 1).each do |i|
                    tag_dep = nil
                    tag_params = {
                          assignment_id: @assignment.id,
              Severity: Minor
              Found in app/models/assignment_form.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

              Avoid too many return statements within this method.
              Open

                      return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
              Severity: Major
              Found in app/models/assignment_form.rb - About 30 mins to fix

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

                  def update_assigned_badges(badge, assignment)
                    if assignment && badge
                      AssignmentBadge.where(assignment_id: assignment[:id]).map(&:id).each do |assigned_badge_id|
                        AssignmentBadge.delete(assigned_badge_id) unless badge[:id].include?(assigned_badge_id)
                      end
                Severity: Minor
                Found in app/models/assignment_form.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

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

                      assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: @assignment.id, used_in_round: round_number)
                      assignment_questionnaires.each do |aq|
                        # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it
                        return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
                      end
                Severity: Minor
                Found in app/models/assignment_form.rb and 2 other locations - About 20 mins to fix
                app/models/assignment_form.rb on lines 249..253
                app/models/assignment_form.rb on lines 270..274

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

                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 3 locations. Consider refactoring.
                Open

                      assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: @assignment.id, topic_id: topic_id)
                      assignment_questionnaires.each do |aq|
                        # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it
                        return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
                      end
                Severity: Minor
                Found in app/models/assignment_form.rb and 2 other locations - About 20 mins to fix
                app/models/assignment_form.rb on lines 249..253
                app/models/assignment_form.rb on lines 263..267

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

                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 3 locations. Consider refactoring.
                Open

                      assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: @assignment.id, duty_id: duty_id)
                      assignment_questionnaires.each do |aq|
                        # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it
                        return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
                      end
                Severity: Minor
                Found in app/models/assignment_form.rb and 2 other locations - About 20 mins to fix
                app/models/assignment_form.rb on lines 263..267
                app/models/assignment_form.rb on lines 270..274

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

                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

                Space missing after comma.
                Open

                            create_or_update_tag_prompt_deployments(questionnaire.id,value)
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                Checks for comma (,) not followed by some kind of space.

                Example:

                # bad
                [1,2]
                { foo:bar,}
                
                # good
                [1, 2]
                { foo:bar, }

                Space missing after comma.
                Open

                          create_or_update_tag_prompt_deployments(key,value)
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                Checks for comma (,) not followed by some kind of space.

                Example:

                # bad
                [1,2]
                { foo:bar,}
                
                # good
                [1, 2]
                { foo:bar, }

                Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
                Open

                            assignment_id: @assignment.id,
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                This cops checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the AlignHash cop.

                By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.

                Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.

                This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:

                Example: EnforcedStyle: specialinsideparentheses (default)

                # The `special_inside_parentheses` style enforces that the first key
                # in a hash literal where the opening brace and the first key are on
                # separate lines is indented one step (two spaces) more than the
                # position inside the opening parentheses.
                
                # bad
                hash = {
                  key: :value
                }
                and_in_a_method_call({
                  no: :difference
                                     })
                
                # good
                special_inside_parentheses
                hash = {
                  key: :value
                }
                but_in_a_method_call({
                                       its_like: :this
                                     })

                Example: EnforcedStyle: consistent

                # The `consistent` style enforces that the first key in a hash
                # literal where the opening brace and the first key are on
                # seprate lines is indented the same as a hash literal which is not
                # defined inside a method call.
                
                # bad
                hash = {
                  key: :value
                }
                but_in_a_method_call({
                                       its_like: :this
                                      })
                
                # good
                hash = {
                  key: :value
                }
                and_in_a_method_call({
                  no: :difference
                })

                Example: EnforcedStyle: align_braces

                # The `align_brackets` style enforces that the opening and closing
                # braces are indented to the same position.
                
                # bad
                and_now_for_something = {
                                          completely: :different
                }
                
                # good
                and_now_for_something = {
                                          completely: :different
                                        }

                Indent the right brace the same as the start of the line where the left brace is.
                Open

                        }
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                This cops checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the AlignHash cop.

                By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.

                Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.

                This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:

                Example: EnforcedStyle: specialinsideparentheses (default)

                # The `special_inside_parentheses` style enforces that the first key
                # in a hash literal where the opening brace and the first key are on
                # separate lines is indented one step (two spaces) more than the
                # position inside the opening parentheses.
                
                # bad
                hash = {
                  key: :value
                }
                and_in_a_method_call({
                  no: :difference
                                     })
                
                # good
                special_inside_parentheses
                hash = {
                  key: :value
                }
                but_in_a_method_call({
                                       its_like: :this
                                     })

                Example: EnforcedStyle: consistent

                # The `consistent` style enforces that the first key in a hash
                # literal where the opening brace and the first key are on
                # seprate lines is indented the same as a hash literal which is not
                # defined inside a method call.
                
                # bad
                hash = {
                  key: :value
                }
                but_in_a_method_call({
                                       its_like: :this
                                      })
                
                # good
                hash = {
                  key: :value
                }
                and_in_a_method_call({
                  no: :difference
                })

                Example: EnforcedStyle: align_braces

                # The `align_brackets` style enforces that the opening and closing
                # braces are indented to the same position.
                
                # bad
                and_now_for_something = {
                                          completely: :different
                }
                
                # good
                and_now_for_something = {
                                          completely: :different
                                        }

                Space missing after comma.
                Open

                            TagPromptDeployment.where(assignment_id: @assignment.id,questionnaire_id: questionnaire.id).destroy_all if value.key?('deleted')
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                Checks for comma (,) not followed by some kind of space.

                Example:

                # bad
                [1,2]
                { foo:bar,}
                
                # good
                [1, 2]
                { foo:bar, }

                Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
                Open

                        if tag_dep
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

                Example:

                # bad
                if condition
                  do_stuff(bar)
                end
                
                unless qux.empty?
                  Foo.do_something
                end
                
                # good
                do_stuff(bar) if condition
                Foo.do_something unless qux.empty?

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

                    if simicheck_delay.to_i >= 0
                Severity: Minor
                Found in app/models/assignment_form.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

                Move assignment_questionnaires.each do |aq| # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type end out of the conditional.
                Open

                      assignment_questionnaires.each do |aq|
                        # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it
                        return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
                      end
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                This cop checks for identical lines at the beginning or end of each branch of a conditional statement.

                Example:

                # bad
                if condition
                  do_x
                  do_z
                else
                  do_y
                  do_z
                end
                
                # good
                if condition
                  do_x
                else
                  do_y
                end
                do_z
                
                # bad
                if condition
                  do_z
                  do_x
                else
                  do_z
                  do_y
                end
                
                # good
                do_z
                if condition
                  do_x
                else
                  do_y
                end
                
                # bad
                case foo
                when 1
                  do_x
                when 2
                  do_x
                else
                  do_x
                end
                
                # good
                case foo
                when 1
                  do_x
                  do_y
                when 2
                  # nothing
                else
                  do_x
                  do_z
                end

                Move assignment_questionnaires.each do |aq| # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type end out of the conditional.
                Open

                      assignment_questionnaires.each do |aq|
                        # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it
                        return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
                      end
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                This cop checks for identical lines at the beginning or end of each branch of a conditional statement.

                Example:

                # bad
                if condition
                  do_x
                  do_z
                else
                  do_y
                  do_z
                end
                
                # good
                if condition
                  do_x
                else
                  do_y
                end
                do_z
                
                # bad
                if condition
                  do_z
                  do_x
                else
                  do_z
                  do_y
                end
                
                # good
                do_z
                if condition
                  do_x
                else
                  do_y
                end
                
                # bad
                case foo
                when 1
                  do_x
                when 2
                  do_x
                else
                  do_x
                end
                
                # good
                case foo
                when 1
                  do_x
                  do_y
                when 2
                  # nothing
                else
                  do_x
                  do_z
                end

                Missing top-level class documentation comment.
                Open

                class AssignmentForm
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                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

                    unless attributes.nil?
                Severity: Minor
                Found in app/models/assignment_form.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

                Trailing whitespace detected.
                Open

                  
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                Use snake_case for variable names.
                Open

                      assignmentId = job.args.first
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

                Example: EnforcedStyle: snake_case (default)

                # bad
                fooBar = 1
                
                # good
                foo_bar = 1

                Example: EnforcedStyle: camelCase

                # bad
                foo_bar = 1
                
                # good
                fooBar = 1

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

                    if @assignment.require_quiz.nil?
                Severity: Minor
                Found in app/models/assignment_form.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

                Move assignment_questionnaires.each do |aq| # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type end out of the conditional.
                Open

                      assignment_questionnaires.each do |aq|
                        # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it
                        return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
                      end
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                This cop checks for identical lines at the beginning or end of each branch of a conditional statement.

                Example:

                # bad
                if condition
                  do_x
                  do_z
                else
                  do_y
                  do_z
                end
                
                # good
                if condition
                  do_x
                else
                  do_y
                end
                do_z
                
                # bad
                if condition
                  do_z
                  do_x
                else
                  do_z
                  do_y
                end
                
                # good
                do_z
                if condition
                  do_x
                else
                  do_y
                end
                
                # bad
                case foo
                when 1
                  do_x
                when 2
                  do_x
                else
                  do_x
                end
                
                # good
                case foo
                when 1
                  do_x
                  do_y
                when 2
                  # nothing
                else
                  do_x
                  do_z
                end

                Move assignment_questionnaires.each do |aq| # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type end out of the conditional.
                Open

                      assignment_questionnaires.each do |aq|
                        # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it
                        return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
                      end
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                This cop checks for identical lines at the beginning or end of each branch of a conditional statement.

                Example:

                # bad
                if condition
                  do_x
                  do_z
                else
                  do_y
                  do_z
                end
                
                # good
                if condition
                  do_x
                else
                  do_y
                end
                do_z
                
                # bad
                if condition
                  do_z
                  do_x
                else
                  do_z
                  do_y
                end
                
                # good
                do_z
                if condition
                  do_x
                else
                  do_y
                end
                
                # bad
                case foo
                when 1
                  do_x
                when 2
                  do_x
                else
                  do_x
                end
                
                # good
                case foo
                when 1
                  do_x
                  do_y
                when 2
                  # nothing
                else
                  do_x
                  do_z
                end

                Use snake_case for variable names.
                Open

                      assignmentId = job.args.first
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

                Example: EnforcedStyle: snake_case (default)

                # bad
                fooBar = 1
                
                # good
                foo_bar = 1

                Example: EnforcedStyle: camelCase

                # bad
                foo_bar = 1
                
                # good
                fooBar = 1

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

                    unless @has_errors
                Severity: Minor
                Found in app/models/assignment_form.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 total_weight.zero? || total_weight == 100
                Severity: Minor
                Found in app/models/assignment_form.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

                Move assignment_questionnaires.each do |aq| # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type end out of the conditional.
                Open

                      assignment_questionnaires.each do |aq|
                        # If the AQ questionnaire matches the type of the questionnaire that needs to be updated, return it
                        return aq if aq.questionnaire_id && Questionnaire.find(aq.questionnaire_id).type == questionnaire_type
                      end
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                This cop checks for identical lines at the beginning or end of each branch of a conditional statement.

                Example:

                # bad
                if condition
                  do_x
                  do_z
                else
                  do_y
                  do_z
                end
                
                # good
                if condition
                  do_x
                else
                  do_y
                end
                do_z
                
                # bad
                if condition
                  do_z
                  do_x
                else
                  do_z
                  do_y
                end
                
                # good
                do_z
                if condition
                  do_x
                else
                  do_y
                end
                
                # bad
                case foo
                when 1
                  do_x
                when 2
                  do_x
                else
                  do_x
                end
                
                # good
                case foo
                when 1
                  do_x
                  do_y
                when 2
                  # nothing
                else
                  do_x
                  do_z
                end

                Prefer Date or Time over DateTime.
                Open

                    curr_time = DateTime.now.in_time_zone('UTC').to_s(:db)
                Severity: Minor
                Found in app/models/assignment_form.rb by rubocop

                This cop checks for uses of DateTime that should be replaced by Date or Time.

                Example:

                # bad - uses `DateTime` for current time
                DateTime.now
                
                # good - uses `Time` for current time
                Time.now
                
                # bad - uses `DateTime` for modern date
                DateTime.iso8601('2016-06-29')
                
                # good - uses `Date` for modern date
                Date.iso8601('2016-06-29')
                
                # good - uses `DateTime` with start argument for historical date
                DateTime.iso8601('1751-04-23', Date::ENGLAND)

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

                    if assignment && badge
                Severity: Minor
                Found in app/models/assignment_form.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

                There are no issues that match your filters.

                Category
                Status