fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/controllers/parents_controller.rb

Summary

Maintainability
A
1 hr
Test Coverage
# File name: parents_controller.rb
# Class name: ParentsController
# Description: Controller used to communicate with the view highways/show
Class has too many lines. [110/100]
ParentsController assumes too much for instance variable '@parent'
ParentsController assumes too much for instance variable '@user'
ParentsController assumes too much for instance variable '@parents'
class ParentsController < ApplicationController
include SessionsHelper
 
Assignment Branch Condition size for index is too high. [26.27/15]
Method has too many lines. [20/10]
Cyclomatic complexity for index is too high. [5/3]
Method `index` has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
ParentsController#index has approx 10 statements
def index
Space inside parentheses detected.
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if ( is_employee? )
ParentsController#index calls 'Parent.all' 3 times
@parents = Parent.all
ParentsController#index calls 'params[:search]' 3 times
if params[:search]
string_to_search = params[:search].strip.upcase!
Prefer single-quoted strings when you don't need string interpolation or special symbols.
puts "AQUI TEM O PARENT"
puts string_to_search
Prefer single-quoted strings when you don't need string interpolation or special symbols.
@parents = Parent.search(string_to_search).order("created_at DESC")
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if (@parents.empty?)
ParentsController#index calls 'flash.now' 2 times
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash.now[:feedback] = "Nenhum secretário(a) encontrado!"
end
if params[:search].blank?
ParentsController#index calls 'Parent.all.order('created_at DESC')' 2 times
@parents = Parent.all.order('created_at DESC')
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash.now[:feedback_warning] = "Digite algo para pesquisar!"
end
else
@parents = Parent.all.order('created_at DESC')
end
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
Cyclomatic complexity for show is too high. [4/3]
def show
id = params[:id]
 
Don't use parentheses around the condition of an `if`.
Space inside parentheses detected.
Use `||` instead of `or`.
if ( is_employee? or verify_parent(id) or is_related?(id) )
@parent = Parent.find(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
ParentsController tests '( is_principal? )' at least 7 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? )
@parent = Parent.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? )
@parent = Parent.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. [11/10]
def create
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? )
@parent = Parent.new(parent_params)
 
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if (@parent.save)
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:success] = "Responsável criado(a) com sucesso"
redirect_to new_parent_alumn_path(@parent)
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. [11/10]
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? )
@parent = Parent.find(params[:id])
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( @parent.update(parent_params) )
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:notice] = "Responsável alterado(a) com sucesso"
redirect_to @parent
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
Don't use parentheses around the condition of an `if`.
Space inside parentheses detected.
Don't use parentheses around a method call.
if ( is_principal? )
@parent = Parent.find(params[:id])
@parent.destroy
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:alert] = "Responsável 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
 
def edit_password_parent
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? )
@user = Parent.find(params[:id])
Prefer single-quoted strings when you don't need string interpolation or special symbols.
render action: "../users/edit_password"
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def update_password_parent
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? )
@user = Parent.find(params[:id])
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if (@user.update!(parent_params))
redirect_to @user
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
render action: "../users/edit_password"
end
else
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`.
private
def parent_params
params.require(:parent).permit(:parent_cpf,
:name,
:address,
:phone,
:gender,
:birth_date)
end
end