fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/controllers/subjects_controller.rb

Summary

Maintainability
A
2 hrs
Test Coverage
# File name: subjects_controller.rb
# Class name: SubjectsController
Line is too long. [83/80]
# Description: Controller used to communicate with the proprietary view of subjects
Class has too many lines. [120/100]
SubjectsController has at least 6 instance variables
SubjectsController assumes too much for instance variable '@subject'
SubjectsController assumes too much for instance variable '@teacher'
SubjectsController assumes too much for instance variable '@classroom_subject'
SubjectsController assumes too much for instance variable '@classroom'
class SubjectsController < ApplicationController
Use 2 (not 1) spaces for indentation.
Tab detected.
include SessionsHelper
 
Inconsistent indentation detected.
def index
Space inside parentheses detected.
Use 2 (not 1) spaces for indentation.
Tab detected.
Don't use parentheses around the condition of an `if`.
Use `||` instead of `or`.
if ( is_principal? or is_teacher? )
Tab detected.
Use 2 (not 1) spaces for indentation.
@subjects = Subject.all
Align `else` with `if`.
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
Tab detected.
end
end
 
Tab detected.
def classroom_subjects
Use 2 (not 1) spaces for indentation.
Tab detected.
@classroom = Classroom.find(params[:id])
Tab detected.
@subjects = @classroom.subjects
Tab detected.
end
 
Inconsistent indentation detected.
def new
SubjectsController tests '( is_principal? )' at least 8 times
Tab detected.
Space inside parentheses detected.
Use 2 (not 1) spaces for indentation.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( is_principal? )
Use 2 (not 0) spaces for indentation.
Tab detected.
@classroom_grades = ClassroomGrade.all
Inconsistent indentation detected.
Tab detected.
@subject = Subject.new
Align `else` with `if`.
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
Tab detected.
end
end
 
Inconsistent indentation detected.
def edit
Space inside parentheses detected.
Tab detected.
Use 2 (not 1) spaces for indentation.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( is_principal? )
Tab detected.
Use 2 (not 0) spaces for indentation.
@classroom_grades = ClassroomGrade.all
Inconsistent indentation detected.
Tab detected.
@subject = Subject.find(params[:id])
Align `else` with `if`.
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
`end` at 35, 4 is not aligned with `if` at 30, 3.
end
end
 
Inconsistent indentation detected.
def show
Tab detected.
Space inside parentheses detected.
Use 2 (not 1) spaces for indentation.
Space after keyword `if` is missing.
if( is_principal? )
Use 2 (not 1) spaces for indentation.
Tab detected.
@subject = Subject.find(params[:id])
Align `else` with `if`.
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
Tab detected.
end
end
 
Method has too many lines. [19/10]
Assignment Branch Condition size for create is too high. [17.03/15]
Cyclomatic complexity for create is too high. [4/3]
Method `create` has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
SubjectsController#create has approx 10 statements
Inconsistent indentation detected.
def create
Space inside parentheses detected.
Tab detected.
Use 2 (not 1) spaces for indentation.
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if ( is_principal? )
Tab detected.
Use 2 (not 0) spaces for indentation.
@classroom_grades = ClassroomGrade.all
Tab detected.
@subject = Subject.new(subject_params)
Tab detected.
@teacher = Teacher.find_by_registry(params[:teacher_registry])
SubjectsController#create performs a nil-check
Space inside parentheses detected.
Tab detected.
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if ( @teacher.nil? )
SubjectsController#create calls '@subject.save' 2 times
Tab detected.
Use 2 (not 1) spaces for indentation.
@subject.save
SubjectsController#create calls 'render 'new'' 2 times
Tab detected.
render 'new'
Tab detected.
else
Tab detected.
Use 2 (not 1) spaces for indentation.
@subject.teacher_id = @teacher.id
Space inside parentheses detected.
Inconsistent indentation detected.
Tab detected.
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if ( @subject.save )
Tab detected.
Use 2 (not 0) spaces for indentation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:success] = "Matéria criada com sucesso"
Inconsistent indentation detected.
Tab detected.
redirect_to @subject
Align `else` with `if`.
Tab detected.
else
Tab detected.
Use 2 (not 1) spaces for indentation.
render 'new'
Tab detected.
`end` at 61, 6 is not aligned with `if` at 56, 5.
end
Tab detected.
`end` at 62, 5 is not aligned with `if` at 51, 3.
end
Align `else` with `if`.
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
Tab detected.
`end` at 65, 2 is not aligned with `if` at 47, 3.
end
end
 
Inconsistent indentation detected.
def destroy
Use 2 (not 1) spaces for indentation.
Space inside parentheses detected.
Tab detected.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( is_principal? )
Use 2 (not 1) spaces for indentation.
Tab detected.
@subject = Subject.find(params[:id])
Tab detected.
@subject.destroy
Inconsistent indentation detected.
Tab detected.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:alert] = "Matéria excluída com sucesso"
Tab detected.
redirect_to subjects_path
Align `else` with `if`.
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
Tab detected.
end
end
 
Method has too many lines. [19/10]
Assignment Branch Condition size for update is too high. [19.87/15]
Cyclomatic complexity for update is too high. [4/3]
Method `update` has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
SubjectsController#update has approx 10 statements
Inconsistent indentation detected.
def update
Use 2 (not 1) spaces for indentation.
Tab detected.
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? )
Use 2 (not 0) spaces for indentation.
Tab detected.
@classroom_grades = ClassroomGrade.all
Tab detected.
@subject = Subject.find(params[:id])
Tab detected.
@teacher = Teacher.find_by_registry(params[:teacher_registry])
SubjectsController#update performs a nil-check
Tab detected.
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( @teacher.nil? )
SubjectsController#update calls '@subject.update(subject_params)' 2 times
Tab detected.
Use 2 (not 1) spaces for indentation.
@subject.update(subject_params)
SubjectsController#update calls 'render 'edit'' 2 times
Tab detected.
render 'edit'
Tab detected.
else
Tab detected.
Use 2 (not 1) spaces for indentation.
@subject.teacher_id = @teacher.id
Tab detected.
Space inside parentheses detected.
Inconsistent indentation detected.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( @subject.update(subject_params) )
Use 2 (not 0) spaces for indentation.
Tab detected.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:notice] = "Matéria alterada com sucesso"
Inconsistent indentation detected.
Tab detected.
redirect_to @subject
Tab detected.
Align `else` with `if`.
else
Tab detected.
Use 2 (not 1) spaces for indentation.
render 'edit'
Tab detected.
`end` at 94, 6 is not aligned with `if` at 89, 5.
end
Tab detected.
`end` at 95, 5 is not aligned with `if` at 84, 3.
end
Align `else` with `if`.
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
Tab detected.
`end` at 98, 2 is not aligned with `if` at 80, 3.
end
end
 
Inconsistent indentation detected.
def add_classrooms
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Use a guard clause instead of wrapping the code inside a conditional expression.
Don't use parentheses around a method call.
if ( is_principal? )
@classroom = Classroom.find(params[:id])
@subjects = Subject.all
end
end
 
Assignment Branch Condition size for add_classroom is too high. [24.23/15]
Method has too many lines. [16/10]
Cyclomatic complexity for add_classroom is too high. [4/3]
SubjectsController#add_classroom has approx 9 statements
Method `add_classroom` has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Inconsistent indentation detected.
def add_classroom
Space inside parentheses detected.
Use a guard clause instead of wrapping the code inside a conditional expression.
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])
@subject = Subject.find(params[:subject_id])
SubjectsController#add_classroom calls '@subject.id' 2 times
SubjectsController#add_classroom calls '@classroom.id' 2 times
Tab detected.
Inconsistent indentation detected.
Don't use parentheses around a method call.
Line is too long. [101/80]
if !((ClassroomSubject.where(classroom_id: @classroom.id).where(subject_id: @subject.id)).exists?)
Use 2 (not 1) spaces for indentation.
Tab detected.
@classroom_subject = ClassroomSubject.new
Tab detected.
@classroom_subject.subject_id = @subject.id
Tab detected.
@classroom_subject.classroom_id = @classroom.id
Tab detected.
if @classroom_subject.save
Use 2 (not 1) spaces for indentation.
Tab detected.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:success] = "Matéria adicionada com sucesso"
SubjectsController#add_classroom calls 'redirect_to add_classrooms_path(@classroom)' 2 times
SubjectsController#add_classroom calls 'add_classrooms_path(@classroom)' 2 times
Tab detected.
redirect_to add_classrooms_path(@classroom)
Tab detected.
end
Tab detected.
else
Use 2 (not 1) spaces for indentation.
Tab detected.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:alert] = "Matéria não pode ser adicionada ou já existe na turma"
Tab detected.
redirect_to add_classrooms_path(@classroom)
Tab detected.
end
end
end
 
Inconsistent indentation detected.
def show_subjects
@classroom = Classroom.find(params[:id])
@subjects = @classroom.subject
end
 
Keep a blank line before and after `private`.
private
Inconsistent indentation detected.
def subject_params
Use 2 (not 1) spaces for indentation.
Tab detected.
params.require(:subject).permit(:name_subject,
Align the parameters of a method call if they span more than one line.
Space missing after comma.
Tab detected.
:class_level,:teacher_id,:classroom_id,:subject_id, :classroom_grade_id)
end
end