testmycode/tmc-server

View on GitHub
app/models/submission.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Submission has 43 methods (exceeds 20 allowed). Consider refactoring.
Open

class Submission < ApplicationRecord
  include Swagger::Blocks

  swagger_schema :Submission do
    key :required, %i[id user_id pretest_error created_at exercise_name course_id processed
Severity: Minor
Found in app/models/submission.rb - About 5 hrs to fix

    File submission.rb has 338 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'zlib'
    require 'securerandom'
    require 'submission_packager'
    
    class Submission < ApplicationRecord
    Severity: Minor
    Found in app/models/submission.rb - About 4 hrs to fix

      Method filter_fields! has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.filter_fields!(submissions)
          submissions.map! do |sub|
            {
              id: sub.id,
              user_id: sub.user_id,
      Severity: Minor
      Found in app/models/submission.rb - About 1 hr to fix

        Method raise_pretest_error_if_any has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def raise_pretest_error_if_any
            unless pretest_error.nil?
              error = "Submission failed: #{pretest_error}."
              error << if stdout.blank?
                "\n\n(no stdout)"
        Severity: Minor
        Found in app/models/submission.rb - About 45 mins to fix

        Cognitive Complexity

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

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

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

        Further reading

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

          def params=(value)
            if value.is_a?(Hash)
              value.each { |k, v| raise "Invalid submission param: #{k} = #{v}" unless valid_param?(k, v) }
              self.params_json = value.to_json
            elsif value.nil?
        Severity: Minor
        Found in app/models/submission.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

        There are no issues that match your filters.

        Category
        Status