fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/controllers/grades_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
# File name: grades_controller.rb
# Class name: GradesController
# Description: Controller used to generate alumns grades
GradesController has at least 5 instance variables
GradesController assumes too much for instance variable '@subject'
GradesController assumes too much for instance variable '@current_user'
GradesController assumes too much for instance variable '@alumn'
GradesController assumes too much for instance variable '@classroom'
GradesController assumes too much for instance variable '@grade'
class GradesController < ApplicationController
include SessionsHelper
 
Do not put a space between a method name and the opening parenthesis.
def self.create (alumn)
alumn.classroom.subjects.each do |subject|
GradesController#self.create calls 'subject.id' 2 times
GradesController#self.create calls 'alumn.id' 2 times
Space missing after colon.
Don't use parentheses around a method call.
Favor `unless` over `if` for negative conditions.
Use `next` to skip iteration.
if !(Grade.where(alumn_id:alumn.id).where(subject_id: subject.id).exists?)
@grade = Grade.new(alumn_id: alumn.id, subject_id: subject.id,
Align the elements of a hash literal if they span more than one line.
classroom_id: alumn.classroom_id)
@grade.save
end
end
end
 
def set_grades
Don't use parentheses around the condition of an `if`.
Use `||` instead of `or`.
Use a guard clause instead of wrapping the code inside a conditional expression.
if (is_secretary? or is_principal?)
@classroom = Classroom.find(params[:id])
@subject = Subject.find(params[:subject_id])
Line is too long. [85/80]
Space missing after colon.
@grades = Grade.where(classroom_id:@classroom.id).where(subject_id:@subject.id)
end
end
 
Do not put a space between a method name and the opening parenthesis.
def self.update_alumn (alumn)
alumn.grades.each do |grade|
grade.classroom_id = alumn.classroom_id
grade.save
end
alumn.classroom.subjects.each do |subject|
Space missing after colon.
Favor `unless` over `if` for negative conditions.
if !Grade.where(alumn_id:alumn.id).where(subject_id: subject.id).exists?
GradesController.create(alumn)
end
end
end
 
Assignment Branch Condition size for post_grades is too high. [20.49/15]
Method has too many lines. [12/10]
GradesController#post_grades has approx 7 statements
def post_grades
Use a guard clause instead of wrapping the code inside a conditional expression.
if is_secretary?
@classroom = Classroom.find(params[:id])
@subject = Subject.find(params[:subject_id])
@alumn = Alumn.find(params[:alumn_id])
Line is too long. [108/80]
@grade = Grade.find_by_classroom_id_and_subject_id_and_alumn_id(@classroom.id, @subject.id, @alumn.id)
if @grade.update(grade_params)
Space missing after comma.
GradeHistoriesController.create(@grade,@current_user)
redirect_to set_grades_path(@classroom, @subject)
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
render "grades/index"
end
end
end
 
Indent access modifiers like `private`.
Keep a blank line before and after `private`.
private
def grade_params
params.require(:grade).permit(:grade_01,
:grade_02,
:grade_03,
:grade_04,
:grade_final,
:alumn_id,
:subject_id)
end
end