autolab/Autolab

View on GitHub
app/controllers/assessment/handin.rb

Summary

Maintainability
F
3 days
Test Coverage

Method local_submit has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

  def local_submit
    @user = User.find_by(email: params[:user])
    @cud = @user ? @course.course_user_data.find_by(user_id: @user.id) : nil
    unless @cud
      err = "ERROR: invalid username (#{params[:user]}) for class #{@course.id}"
Severity: Minor
Found in app/controllers/assessment/handin.rb - About 7 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 local_submit has 108 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def local_submit
    @user = User.find_by(email: params[:user])
    @cud = @user ? @course.course_user_data.find_by(user_id: @user.id) : nil
    unless @cud
      err = "ERROR: invalid username (#{params[:user]}) for class #{@course.id}"
Severity: Major
Found in app/controllers/assessment/handin.rb - About 4 hrs to fix

    File handin.rb has 301 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require "pathname"
    
    ##
    # Handles different handin methods, including web form, local_submit and log_submit
    #
    Severity: Minor
    Found in app/controllers/assessment/handin.rb - About 3 hrs to fix

      Method handin has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

        def handin
          if @assessment.disable_handins?
            flash[:error] = "Sorry, handins are disabled for this assessment."
            redirect_to(action: :show)
            return false
      Severity: Minor
      Found in app/controllers/assessment/handin.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 handin has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def handin
          if @assessment.disable_handins?
            flash[:error] = "Sorry, handins are disabled for this assessment."
            redirect_to(action: :show)
            return false
      Severity: Major
      Found in app/controllers/assessment/handin.rb - About 2 hrs to fix

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

          def log_submit
            @user = User.find_by(email: params[:user])
            @cud = @user ? @course.course_user_data.find_by(user_id: @user.id) : nil
            unless @cud
              err = "ERROR: invalid username (#{params[:user]}) for class #{@course.id}"
        Severity: Major
        Found in app/controllers/assessment/handin.rb - About 2 hrs to fix

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

            def log_submit
              @user = User.find_by(email: params[:user])
              @cud = @user ? @course.course_user_data.find_by(user_id: @user.id) : nil
              unless @cud
                err = "ERROR: invalid username (#{params[:user]}) for class #{@course.id}"
          Severity: Minor
          Found in app/controllers/assessment/handin.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

          Avoid too many return statements within this method.
          Open

              redirect_to([:history, @course, @assessment]) && return
          Severity: Major
          Found in app/controllers/assessment/handin.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                      render(plain: flash[:error], status: :bad_request) && return
            Severity: Major
            Found in app/controllers/assessment/handin.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                    render(plain: "Successfully submitted\n") && return
              Severity: Major
              Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                          render(plain: "Invalid path to file", status: :bad_request) && return
                Severity: Major
                Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                        redirect_to(action: :show) && return
                  Severity: Major
                  Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                        render(plain: remote_handin_dir) && return
                    Severity: Major
                    Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                          render(plain: "OK", status: 200) && return
                      Severity: Major
                      Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                render(plain: err, status: :bad_request) && return
                        Severity: Major
                        Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  render(plain: " - You have #{remaining} submissions left\n") && return
                          Severity: Major
                          Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                  render(plain: "OK", status: 200) && return if scores.keys.length == 0
                            Severity: Major
                            Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                                 status: :bad_request) && return
                              Severity: Major
                              Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                          render(plain: "WARNING: could not clear previous handin directory, please") && return
                                Severity: Major
                                Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          render(plain: flash[:error], status: :bad_request) && return unless validateHandinForGroups_forHTML
                                  Severity: Major
                                  Found in app/controllers/assessment/handin.rb - About 30 mins to fix

                                    There are no issues that match your filters.

                                    Category
                                    Status