fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/controllers/classrooms_controller.rb

Summary

Maintainability
A
2 hrs
Test Coverage
# File name: classrooms_controller.rb
# Class name: ClassroomsController
Line is too long. [85/80]
# Description: Controller used to communicate with the proprietary view of classrooms
Class has too many lines. [118/100]
ClassroomsController has at least 8 instance variables
ClassroomsController assumes too much for instance variable '@alumn'
ClassroomsController assumes too much for instance variable '@classroom'
ClassroomsController assumes too much for instance variable '@classrooms'
class ClassroomsController < ApplicationController
include SessionsHelper
 
Assignment Branch Condition size for index is too high. [21.47/15]
Method has too many lines. [14/10]
Cyclomatic complexity for index is too high. [6/3]
Method `index` has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
def index
Space inside parentheses detected.
Use `||` instead of `or`.
Don't use parentheses around the condition of an `if`.
if ( is_principal? or is_secretary? )
@classrooms = Classroom.all.order('name_classroom')
ClassroomsController#index calls 'params[:classroom_grade_id]' 2 times
unless params[:classroom_grade_id].blank?
Line is too long. [87/80]
@classrooms &= Classroom.where(classroom_grade_id: params[:classroom_grade_id])
end
ClassroomsController#index calls 'params[:shift_id]' 2 times
unless params[:shift_id].blank?
@classrooms &= Classroom.where(shift_id: params[:shift_id])
end
Favor modifier `if` usage when having a single-line body. Another good alternative is the usage of control flow `&&`/`||`.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if (@classrooms.empty?)
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash.now[:notice] = "Nenhuma Turma encontrada!"
end
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def new
ClassroomsController tests '( is_principal? )' at least 7 times
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? )
@classroom = Classroom.new
@classroom_grades = ClassroomGrade.all
@shifts = Shift.all
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def show
Use `||` instead of `or`.
Don't use parentheses around the condition of an `if`.
Space inside parentheses detected.
if ( is_principal? or is_secretary?)
@classroom = Classroom.find(params[:id])
@shift = Shift.find_by_id(@classroom.shift_id)
Line is too long. [81/80]
@classroom_grade = ClassroomGrade.find_by_id(@classroom.classroom_grade_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. [13/10]
ClassroomsController#create has approx 7 statements
def create
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? )
@classroom = Classroom.create(classroom_params)
@classroom_grades = ClassroomGrade.all
@shifts = Shift.all
Don't use parentheses around the condition of an `if`.
Space inside parentheses detected.
Don't use parentheses around a method call.
if ( @classroom.save )
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:success] = "Turma criada com sucesso"
redirect_to classroom_path(@classroom)
else
render 'classrooms/new'
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
Use 2 (not 0) spaces for indentation.
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? )
@classroom = Classroom.find(params[:id])
@classroom.destroy
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:alert] = "Turma excluída com sucesso"
redirect_to users_path
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` at 69, 0 is not aligned with `def` at 60, 2.
end
 
Inconsistent indentation detected.
def edit
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? )
@classroom = Classroom.find(params[:id])
@classroom_grades = ClassroomGrade.all
@shifts = Shift.all
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Use 2 (not 4) spaces for indentation.
redirect_to "/errors/error_500"
end
end
 
Method has too many lines. [13/10]
ClassroomsController#update has approx 7 statements
Inconsistent indentation detected.
def update
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? )
@classroom = Classroom.find(params[:id])
@classroom_grades = ClassroomGrade.all
@shifts = Shift.all
if @classroom.update(classroom_params)
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:notice] = "Turma alterada com sucesso"
redirect_to classroom_path(@classroom)
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
render "classrooms/edit"
end
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
 
Inconsistent indentation detected.
def add_alumns
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? )
@classroom = Classroom.find(params[:id])
@alumns = @classroom.alumns.order('name')
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
 
Method has too many lines. [18/10]
Assignment Branch Condition size for add_alumn is too high. [17.72/15]
Cyclomatic complexity for add_alumn is too high. [4/3]
Method `add_alumn` has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
ClassroomsController#add_alumn has approx 9 statements
Inconsistent indentation detected.
def add_alumn
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? )
@classroom = Classroom.find(params[:id])
@alumns = @classroom.alumns
@alumn = Alumn.find_by_registry(params[:registry])
ClassroomsController#add_alumn performs a nil-check
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
Don't use parentheses around a variable.
if ( (@alumn).nil? )
redirect_to add_alumns_path(@classroom)
else
@alumn.classroom_id = @classroom.id
if @alumn.save
GradesController.update_alumn(@alumn)
ClassroomsController#add_alumn calls 'render "classrooms/add_alumns"' 2 times
Move `render "classrooms/add_alumns"` out of the conditional.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
render "classrooms/add_alumns"
else
Move `render "classrooms/add_alumns"` out of the conditional.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
render "classrooms/add_alumns"
end
end
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
 
Keep a blank line before and after `private`.
Indent access modifiers like `private`.
private
def classroom_params
params.require(:classroom).permit(:name_classroom,
:shift_id,
:classroom_grade_id)
end
end