fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/controllers/sessions_controller.rb

Summary

Maintainability
A
2 hrs
Test Coverage
Missing space after `#`.
#File name: session_controller.rb
Missing space after `#`.
#Class name: SessionsController
Missing space after `#`.
#Description: Control the session login of the users
SessionsController assumes too much for instance variable '@user'
class SessionsController < ApplicationController
include SessionsHelper
include ReaderHelper
include SchoolMissesHelper
 
Assignment Branch Condition size for create is too high. [52.52/15]
Method has too many lines. [30/10]
Cyclomatic complexity for create is too high. [12/3]
Perceived complexity for create is too high. [16/7]
Method `create` has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Method `create` has 30 lines of code (exceeds 25 allowed). Consider refactoring.
SessionsController#create has approx 14 statements
def create
SessionsController#create calls 'Alumn.find_by_registry(params[:login])' 2 times
SessionsController#create calls 'params[:login]' 6 times
SessionsController#create performs a nil-check
Space inside parentheses detected.
Don't use parentheses around an unary operation.
Don't use parentheses around the condition of an `if`.
if ( !Alumn.find_by_registry(params[:login]).nil? )
@user = Alumn.find_by_registry(params[:login])
SessionsController#create calls 'Parent.find_by_login(params[:login])' 2 times
Space inside parentheses detected.
Don't use parentheses around an unary operation.
Don't use parentheses around the condition of an `elsif`.
elsif ( !Parent.find_by_login(params[:login]).nil? )
@user = Parent.find_by_login(params[:login])
SessionsController#create calls 'Employee.find_by_registry(params[:login])' 2 times
Space inside parentheses detected.
Don't use parentheses around the condition of an `elsif`.
Don't use parentheses around an unary operation.
elsif ( !Employee.find_by_registry(params[:login]).nil? )
@user = Employee.find_by_registry(params[:login])
end
 
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Use `&&` instead of `and`.
if ( @user and @user.authenticate(params[:password]) )
cookies[:authorization_token] = @user.authorization_token
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if (is_alumn?)
redirect_to alumn_path(@user)
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `elsif`.
elsif (is_parent?)
redirect_to parent_alumns_path(@user)
Don't use parentheses around the condition of an `elsif`.
Don't use parentheses around a method call.
elsif (is_teacher?)
redirect_to teacher_path(@user)
Space after keyword `elsif` is missing.
elsif(is_secretary?)
redirect_to secretary_path(@user)
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `elsif`.
elsif (is_principal?)
redirect_to users_path
end
 
# Se chegou aqui conseguiu fazer o login
Do not use parentheses for method calls with no arguments.
date = mountCurrentDate()
data_exists = check_if_date_exits(date)
Space after keyword `if` is missing.
if(data_exists == false)
Missing space after `#`.
#create new data
give_fault_to_all_alumns(date)
Space missing after colon.
DayOfClass.create(date:date)
Redundant `else`-clause.
else
Missing space after `#`.
#data already exists
Missing space after `#`.
#nothing to do
end
 
Extra blank line detected.
 
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to root_url, notice: "Login e/ou senha incorreta(s)!"
end
end
 
def destroy
cookies.delete(:authorization_token)
redirect_to root_url
end
 
Extra blank line detected.
 
SessionsController#check_if_date_exits doesn't depend on instance state (maybe move it to another class?)
Use empty lines between method definitions.
def check_if_date_exits(date)
days_of_class = DayOfClass.all
 
data_exists = false
Prefer `each` over `for`.
for day_of_class in days_of_class
 
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`.
if (day_of_class.date.to_s == date.to_s)
Do not use semicolons to terminate expressions.
data_exists = true;
end
end
 
Redundant `return` detected.
return data_exists
end
 
Put empty method definitions on a single line.
def login_helper
end
Extra empty line detected at class body end.
 
end