fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/controllers/teachers_controller.rb

Summary

Maintainability
A
25 mins
Test Coverage
require 'set'
 
Class has too many lines. [107/100]
TeachersController has at least 9 instance variables
TeachersController assumes too much for instance variable '@classroom'
TeachersController assumes too much for instance variable '@classrooms'
TeachersController has no descriptive comment
TeachersController assumes too much for instance variable '@subject'
TeachersController assumes too much for instance variable '@teacher'
TeachersController assumes too much for instance variable '@classroom_subjects'
TeachersController assumes too much for instance variable '@subjects'
Missing top-level class documentation comment.
class TeachersController < ApplicationController
Extra empty line detected at class body beginning.
 
include SessionsHelper
 
def index
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( is_employee? )
@teachers = Teacher.all
else
Use 2 (not 4) spaces for indentation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def show
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
Space inside parentheses detected.
if ( is_employee? )
@teacher = Teacher.find(params[:id])
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def new
TeachersController tests '( is_principal? )' at least 5 times
Space inside parentheses detected.
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if ( is_principal? )
@shifts = Shift.all
@teacher = Teacher.new
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def edit
Space inside parentheses detected.
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if ( is_principal? )
@shifts = Shift.all
@teacher = Teacher.find(params[:id])
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
Method has too many lines. [12/10]
TeachersController#create has approx 6 statements
def create
Don't use parentheses around a method call.
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
if ( is_principal? )
@shifts = Shift.all
@teacher = Teacher.new(teacher_params)
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if (@teacher.save)
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:success] = "Professor(a) criado(a) com sucesso"
redirect_to users_path
else
render 'new'
end
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
Method has too many lines. [12/10]
TeachersController#update has approx 6 statements
Similar blocks of code found in 2 locations. Consider refactoring.
def update
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
Space inside parentheses detected.
if ( is_principal? )
@shifts = Shift.all
@teacher = Teacher.find(params[:id])
Don't use parentheses around the condition of an `if`.
Space inside parentheses detected.
Don't use parentheses around a method call.
if ( @teacher.update(teacher_params) )
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:notice] = "Professor(a) alterado(a) com sucesso"
redirect_to @teacher
else
render 'edit'
end
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def destroy
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( is_principal? )
@teacher = Teacher.find(params[:id])
@teacher.destroy
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:alert] = "Professor(a) excluído(a) com sucesso"
redirect_to users_path
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
TeachersController#teacher_classrooms has approx 6 statements
def teacher_classrooms
Prefer single-quoted strings when you don't need string interpolation or special symbols.
@subjects = Subject.where("teacher_id = ?", params[:id])
@classrooms = Set.new
@subjects.each do |subject|
Prefer single-quoted strings when you don't need string interpolation or special symbols.
relations = ClassroomSubject.where("subject_id = ?", subject.id)
TeachersController#teacher_classrooms contains iterators nested 2 deep
relations.each do |relation|
@classrooms.add(Classroom.find_by_id(relation.classroom_id))
end
end
end
 
def teacher_classroom_subjects
Prefer single-quoted strings when you don't need string interpolation or special symbols.
@subjects = Subject.where("teacher_id = ?", params[:teacher_id])
@classroom_subjects = []
@subjects.each do |subject|
@classroom_subjects << subject
end
end
 
def teacher_grades
@classroom = Classroom.find(params[:classroom_id])
@subject = Subject.find(params[:subject_id])
Line is too long. [85/80]
@grades = Grade.where(classroom_id: @classroom.id).where(subject_id: @subject.id)
end
 
Keep a blank line before and after `private`.
Indent access modifiers like `private`.
private
Method has too many lines. [12/10]
def teacher_params
params.require(:teacher).permit(:registry,
Align the parameters of a method call if they span more than one line.
:admission_date,
Align the parameters of a method call if they span more than one line.
:employee_cpf,
Align the parameters of a method call if they span more than one line.
:shift,
Align the parameters of a method call if they span more than one line.
:password,
Align the parameters of a method call if they span more than one line.
:name,
Align the parameters of a method call if they span more than one line.
:address,
Align the parameters of a method call if they span more than one line.
:phone,
Align the parameters of a method call if they span more than one line.
:gender,
Align the parameters of a method call if they span more than one line.
:birth_date,
Align the parameters of a method call if they span more than one line.
:admission_date,
Align the parameters of a method call if they span more than one line.
:shift_id)
end
end