fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/controllers/secretaries_controller.rb

Summary

Maintainability
A
1 hr
Test Coverage
# File name: secretaries_controller.rb
# Class name: SecretariesController
Line is too long. [86/80]
# Description: Controller used to communicate with the proprietary view of secretaries
SecretariesController assumes too much for instance variable '@secretaries'
SecretariesController assumes too much for instance variable '@secretary'
class SecretariesController < ApplicationController
Tab detected.
Use 2 (not 1) spaces for indentation.
include SessionsHelper
 
Assignment Branch Condition size for index is too high. [24.37/15]
Method has too many lines. [18/10]
Cyclomatic complexity for index is too high. [5/3]
Method `index` has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
SecretariesController#index has approx 8 statements
Inconsistent indentation detected.
def index
SecretariesController tests '( is_principal? )' at least 6 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? )
SecretariesController#index calls 'Secretary.all' 3 times
@secretaries = Secretary.all
SecretariesController#index calls 'params[:search]' 3 times
if params[:search]
string_to_search = params[:search].strip.upcase!
Line is too long. [82/80]
Prefer single-quoted strings when you don't need string interpolation or special symbols.
@secretaries = Secretary.search(string_to_search).order("created_at DESC")
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if (@secretaries.empty?)
SecretariesController#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?
SecretariesController#index calls 'Secretary.all.order('created_at DESC')' 2 times
@secretaries = Secretary.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
@secretaries = Secretary.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
 
Inconsistent indentation detected.
def show
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Use `||` instead of `or`.
if ( is_principal? or is_secretary? )
@secretary = Secretary.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
 
Inconsistent indentation detected.
def new
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? )
Tab detected.
Use 2 (not -1) spaces for indentation.
@shifts = Shift.all
Inconsistent indentation detected.
@secretary = Secretary.new
else
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 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? )
Use 2 (not -1) spaces for indentation.
Tab detected.
@shifts = Shift.all
Inconsistent indentation detected.
@secretary = Secretary.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]
SecretariesController#create has approx 6 statements
Inconsistent indentation detected.
def create
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? )
Tab detected.
Use 2 (not -1) spaces for indentation.
@shifts = Shift.all
Inconsistent indentation detected.
@secretary = Secretary.new(secretary_params)
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
Inconsistent indentation detected.
if (@secretary.save)
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:success] = "Secretário(a) criado(a) com sucesso"
redirect_to @secretary
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]
SecretariesController#update has approx 6 statements
Similar blocks of code found in 2 locations. Consider refactoring.
Inconsistent indentation detected.
def update
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? )
Use 2 (not -1) spaces for indentation.
Tab detected.
@shifts = Shift.all
Inconsistent indentation detected.
@secretary = Secretary.find(params[:id])
Inconsistent indentation detected.
if @secretary.update secretary_params
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:notice] = "Secretário(a) alterado(a) com sucesso"
redirect_to @secretary
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
 
Inconsistent indentation detected.
def destroy
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? )
@secretary = Secretary.find(params[:id])
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if (@secretary.destroy)
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:alert] = "Secretário(a) excluído(a) com sucesso"
Tab detected.
Inconsistent indentation detected.
redirect_to secretaries_path
else
Tab detected.
Use 2 (not 1) spaces for indentation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
end
 
Keep a blank line before and after `private`.
private
Method has too many lines. [12/10]
Inconsistent indentation detected.
def secretary_params
Space inside parentheses detected.
Tab detected.
Use 2 (not 1) spaces for indentation.
params.require(:secretary).permit( :employee_cpf,
Align the parameters of a method call if they span more than one line.
Tab detected.
:admission_date,
Align the parameters of a method call if they span more than one line.
Tab detected.
:shift,
Align the parameters of a method call if they span more than one line.
Tab detected.
:name,
Tab detected.
Align the parameters of a method call if they span more than one line.
:address,
Tab detected.
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.
Tab detected.
:gender,
Tab detected.
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.
Tab detected.
:permission,
Align the parameters of a method call if they span more than one line.
Tab detected.
:password,
Tab detected.
Align the parameters of a method call if they span more than one line.
:registry,
Tab detected.
Align the parameters of a method call if they span more than one line.
:shift_id)
end
end