Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.
Method save_all_questions has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
New
def save_all_questions
questionnaire_id = params[:id]
begin
if params[:save]
params[:question].each_pair do |k, v|
Severity: Minor
Found in app/controllers/questionnaires_controller.rb - About 45 mins to fix
Assignment Branch Condition size for save_all_questions is too high. [26.78/15]
Severity: Minor
wontfix: Although code is long and has two nested loops. No need to make changes.
There is a method called create_questionnaire used. Is it used? There are no immediately apparent calls to it. The name is wrong (should be just create, but there is another, different create method). If not, remove create_questionnaire and the tests that test it. [It is not used, but it assigns a creator ID (instructor of the class) whereas create does not.]
New
def save_all_questions
questionnaire_id = params[:id]
begin
if params[:save]
params[:question].each_pair do |k, v|
Severity: Minor
Found in app/controllers/questionnaires_controller.rb - About 45 mins to fix
Assignment Branch Condition size for save_all_questions is too high. [26.78/15]
Severity: Minor
Assignment Branch Condition size for copy is too high. [20.64/15]
New
def copy
begin
instructor_id = session[:user].instructor_id @questionnaire = Questionnaire.copy_questionnaire_details(params, instructor_id)
p_folder = TreeFolder.find_by(name: @questionnaire.display_type)
Severity: Minor
Several methods have a questionnaire_id as a parameter. It’s not clear that it’s necessary, since it seems just to be params[:id] for the questionnaire in use.
WONT FIX NOTE: The questionnaire_id parameter is passed to multiple private methods, and is needed then. Therefore, it is most readable to set questionnaire_id = params[:id] immediately, to ultimately improve consistency throughout file.
Like the weights referred to above, there are other values that are hardwired into the code, especially in add_new_questions. A 0–5 scale for rubric criteria should not be wired in, nor should min and max labels. These variables (alternatives, min_label, max_label) should be, and probably are, set somewhere in the UI. Textfield sizes are OK to default to the sizes given, but they should be defined constants, not literal values in an assignment statement.
There are three checks for whether a questionnaire is a QuizQuestionnaire. Testing the class of an object is always suspect, though in a controller, which has to control a whole hierarchy of objects, it is not necessarily wrong. However, they probably aren’t necessary.
One of the checks is in create_questionnaire. [method may be removed]
One of them deals with weights for a question, which is a kludge or hack, since managing weights should really be done in the model (superclass Questionnaire or subclass QuizQuestionnaire).
The third check has something to do with TreeNodes, which are Expertiza’s way of displaying objects (such as courses and assignments) that need to be shown in a hierarchy. It’s not clear what’s going on here, but I doubt that QuizQuestionnaire really has to be special.
The create method itself is 49 lines long. This is much too long to be viewable at a glance. Break it up into other methods whose names are clear enough to be self-documenting.
Do not use Time.now without zone. Use one of Time.zone.now, Time.current, Time.now.in_time_zone, Time.now.utc, Time.now.getlocal, Time.now.iso8601, Time.now.jisx0301, Time.now.rfc3339, Time.now.to_i, Time.now.to_f instead.