expertiza/expertiza

View on GitHub
app/controllers/courses_controller.rb

Summary

Maintainability
A
35 mins
Test Coverage
F
0%

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

class CoursesController < ApplicationController
  include AuthorizationHelper

  autocomplete :user, :name
  require 'fileutils'

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

  def add_ta
    @course = Course.find(params[:course_id])
    @user = User.find_by(name: params[:user][:name])
    if @user.nil?
      flash.now[:error] = 'The user inputted "' + params[:user][:name] + '" does not exist.'

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 copy
    orig_course = Course.find(params[:id])
    new_course = orig_course.dup
    new_course.instructor_id = session[:user].id
    new_course.name = 'Copy of ' + orig_course.name

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

  def copy
    orig_course = Course.find(params[:id])
    new_course = orig_course.dup
    new_course.instructor_id = session[:user].id
    new_course.name = 'Copy of ' + orig_course.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

Assignment Branch Condition size for update is too high. [24.52/15]
Open

  def update
    @course = Course.find(params[:id])
    unless params[:course][:directory_path].nil? || @course.directory_path == params[:course][:directory_path]
      begin
        FileHelper.delete_directory(@course)

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

  def set_course_fields(_course)
    @course.name = params[:course][:name]
    @course.institutions_id = params[:course][:institutions_id]
    @course.directory_path = params[:course][:directory_path]
    @course.info = params[:course][:info]

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

  def update
    @course = Course.find(params[:id])
    unless params[:course][:directory_path].nil? || @course.directory_path == params[:course][:directory_path]
      begin
        FileHelper.delete_directory(@course)

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

  def add_ta
    @course = Course.find(params[:course_id])
    @user = User.find_by(name: params[:user][:name])
    if @user.nil?
      flash.now[:error] = 'The user inputted "' + params[:user][:name] + '" does not exist.'

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

  def create
    @course = Course.new
    set_course_fields(@course)
    @course.instructor_id = session[:user].id
    begin

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

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

  def remove_ta
    @ta_mapping = TaMapping.find(params[:id])
    @ta = User.find(@ta_mapping.ta_id)

    # if the user does not have any other TA mappings, then the role should be changed to student

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

  def remove_ta
    @ta_mapping = TaMapping.find(params[:id])
    @ta = User.find(@ta_mapping.ta_id)

    # if the user does not have any other TA mappings, then the role should be changed to student

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 7 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    @course = Course.find(params[:id])
    unless params[:course][:directory_path].nil? || @course.directory_path == params[:course][:directory_path]
      begin
        FileHelper.delete_directory(@course)
Severity: Minor
Found in app/controllers/courses_controller.rb - About 35 mins to fix

Cognitive Complexity

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

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

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

Further reading

Do not prefix writer method names with set_.
Open

  def set_course_fields(_course)

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