fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/controllers/strikes_controller.rb

Summary

Maintainability
A
1 hr
Test Coverage
# File name: strikes_controller.rb
# Class name: StrikesController
Line is too long. [82/80]
# Description: Controller used to communicate with the proprietary view of strikes
StrikesController assumes too much for instance variable '@alumn'
StrikesController assumes too much for instance variable '@current_user'
StrikesController assumes too much for instance variable '@strike'
class StrikesController < ApplicationController
include SessionsHelper
 
Cyclomatic complexity for index is too high. [4/3]
def index
id = params[:alumn_id]
 
Space inside parentheses detected.
Use `||` instead of `or`.
Don't use parentheses around the condition of an `if`.
if ( is_employee? or verify_alumn(id) or is_son?(id) )
StrikesController declares the class variable '@@alumn'
Replace class var @@alumn with a class instance var.
@@alumn = Alumn.find(id)
@strikes = @@alumn.strikes
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def new
StrikesController tests '( is_employee? )' at least 5 times
Don't use parentheses around a method call.
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
if ( is_employee? )
Replace class var @@alumn with a class instance var.
@@alumn = Alumn.find(params[:alumn_id])
@strike = Strike.new
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def show
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
Space inside parentheses detected.
if ( logged_in? )
@strike = Strike.find(params[:id])
@alumn = Alumn.find_by_id(@strike.alumn_id)
@employee = Employee.find(@strike.employee_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. [17/10]
Cyclomatic complexity for create is too high. [4/3]
Method `create` has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
StrikesController#create has approx 8 statements
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_employee? )
@strike = @@alumn.strikes.create(strike_params)
@strike.employee_id = @current_user.id
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if (@strike.save)
@@alumn.quantity_strike += 1
if @@alumn.save
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:success] = "AdvertĂȘncia criada com sucesso"
Space missing after comma.
redirect_to alumn_strike_path(@@alumn,@strike)
else
StrikesController#create calls 'render 'strikes/new'' 2 times
render 'strikes/new'
end
else
render 'strikes/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. [13/10]
Cyclomatic complexity for destroy is too high. [4/3]
StrikesController#destroy has approx 6 statements
Method `destroy` has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
def destroy
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( is_employee? )
@strike = Strike.find(params[:id])
@alumn = Alumn.find_by_id(@strike.alumn_id)
if @strike.destroy
@alumn.quantity_strike -= 1
if @alumn.save
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:alert] = "AdvertĂȘncia excluĂ­da com sucesso"
redirect_to users_path
end
end
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
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_employee? )
@strike = Strike.find(params[:id])
@alumn = Alumn.find_by_id(@strike.alumn_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]
Similar blocks of code found in 2 locations. Consider refactoring.
def update
Don't use parentheses around a method call.
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
if ( is_employee? )
@strike = Strike.find(params[:id])
if @strike.update(strike_params)
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:notice] = "AdvertĂȘncia alterada com sucesso"
redirect_to strike_path(@strike)
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
render "strikes/edit"
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 strike_params
params.require(:strike).permit(:description_strike,
Align the parameters of a method call if they span more than one line.
:date_strike,
Align the parameters of a method call if they span more than one line.
employee_attributes: [:employee_id],
alumn_attributes: [:alumn_id])
end
end