expertiza/expertiza

View on GitHub
app/models/assignment_participant.rb

Summary

Maintainability
B
4 hrs
Test Coverage
A
94%

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

class AssignmentParticipant < Participant
  belongs_to  :assignment, class_name: 'Assignment', foreign_key: 'parent_id'
  has_many    :review_mappings, class_name: 'ReviewResponseMap', foreign_key: 'reviewee_id'
  has_many    :response_maps, foreign_key: 'reviewee_id'
  has_many    :quiz_mappings, class_name: 'QuizResponseMap', foreign_key: 'reviewee_id'

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

  def review_file_path(response_map_id = nil, participant = nil)
    if response_map_id.nil?
      return if participant.nil?

      no_team_path = assignment.path + '/' + participant.name.parameterize(separator: '_') + '_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

Class AssignmentParticipant has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

class AssignmentParticipant < Participant
  belongs_to  :assignment, class_name: 'Assignment', foreign_key: 'parent_id'
  has_many    :review_mappings, class_name: 'ReviewResponseMap', foreign_key: 'reviewee_id'
  has_many    :response_maps, foreign_key: 'reviewee_id'
  has_many    :quiz_mappings, class_name: 'QuizResponseMap', foreign_key: 'reviewee_id'
Severity: Minor
Found in app/models/assignment_participant.rb - About 2 hrs to fix

    Assignment Branch Condition size for import is too high. [20.05/15]
    Open

      def self.import(row_hash, _row_header = nil, session, id)
        raise ArgumentError, 'No user id has been specified.' if row_hash.empty?
    
        user = User.find_by(name: row_hash[:username])
    
    

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

      def set_handle
        self.handle = if user.handle.nil? || (user.handle == '')
                        user.name
                      elsif AssignmentParticipant.exists?(parent_id: assignment.id, handle: user.handle)
                        user.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. [11/10]
    Open

      def self.import(row_hash, _row_header = nil, session, id)
        raise ArgumentError, 'No user id has been specified.' if row_hash.empty?
    
        user = User.find_by(name: row_hash[:username])
    
    

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

      def stage_deadline
        topic_id = SignedUpTeam.topic_id(parent_id, user_id)
        stage = assignment.stage_deadline(topic_id)
        if stage == 'Finished'
          return (assignment.staggered_deadline? ? TopicDueDate.find_by(parent_id: topic_id).try(:last).try(:due_at) : assignment.due_dates.last.due_at).to_s

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

      def self.import(row_hash, _row_header = nil, session, id)
        raise ArgumentError, 'No user id has been specified.' if row_hash.empty?
    
        user = User.find_by(name: row_hash[:username])
    
    
    Severity: Minor
    Found in app/models/assignment_participant.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 review_file_path has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def review_file_path(response_map_id = nil, participant = nil)
        if response_map_id.nil?
          return if participant.nil?
    
          no_team_path = assignment.path + '/' + participant.name.parameterize(separator: '_') + '_review'
    Severity: Minor
    Found in app/models/assignment_participant.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

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

      def files(directory)
        files_list = Dir[directory + '/*']
        files = []
    
        files_list.each do |file|
    Severity: Minor
    Found in app/models/assignment_participant.rb and 1 other location - About 35 mins to fix
    app/models/assignment_team.rb on lines 172..183

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 34.

    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

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

        if user.nil?
          raise ArgumentError, "The record containing #{row_hash[:username]} does not have enough items." if row_hash.length < 4
    
          # define_attributes method will return an element that stores values from the row_hash.
          attributes = ImportFileHelper.define_attributes(row_hash)
    Severity: Minor
    Found in app/models/assignment_participant.rb and 1 other location - About 15 mins to fix
    app/models/course_participant.rb on lines 19..23

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

    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

    Do not prefix writer method names with set_.
    Open

      def set_current_user(current_user); end

    This cop makes sure that accessor methods are named properly.

    Example:

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

    Missing top-level class documentation comment.
    Open

    class AssignmentParticipant < Participant

    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

    Do not prefix reader method names with get_.
    Open

      def get_reviewer

    This cop makes sure that accessor methods are named properly.

    Example:

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

    There are no issues that match your filters.

    Category
    Status