fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/controllers/suspensions_controller.rb

Summary

Maintainability
A
1 hr
Test Coverage
# File name: suspensions_controller.rb
# Class name: SuspensionsController
Line is too long. [86/80]
# Description: Controller used to communicate with the proprietary view of suspensions
SuspensionsController assumes too much for instance variable '@current_user'
SuspensionsController assumes too much for instance variable '@suspension'
SuspensionsController assumes too much for instance variable '@alumn'
class SuspensionsController < ApplicationController
Use 2 (not 1) spaces for indentation.
Tab detected.
include SessionsHelper
 
Cyclomatic complexity for index is too high. [4/3]
Tab detected.
def index
Use 2 (not 0) spaces for indentation.
Tab detected.
id = params[:alumn_id]
 
Use `||` instead of `or`.
Space inside parentheses detected.
Inconsistent indentation detected.
Don't use parentheses around the condition of an `if`.
if ( is_employee? or verify_alumn(id) or is_son?(id) )
SuspensionsController declares the class variable '@@alumn'
Tab detected.
Replace class var @@alumn with a class instance var.
Use 2 (not 3) spaces for indentation.
@@alumn = Alumn.find(id)
Tab detected.
Inconsistent indentation detected.
@suspensions = @@alumn.suspensions
Tab detected.
Align `else` with `if`.
else
Use 2 (not 5) spaces for indentation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
`end` at 16, 2 is not aligned with `def` at 7, 1.
end
 
Tab detected.
def new
SuspensionsController tests '( is_principal? )' at least 5 times
Use 2 (not 1) spaces for indentation.
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Tab detected.
Don't use parentheses around a method call.
if ( is_principal? )
Use 2 (not 1) spaces for indentation.
Tab detected.
Replace class var @@alumn with a class instance var.
@@alumn = Alumn.find(params[:alumn_id])
Tab detected.
@suspension = Suspension.new
Tab detected.
else
Use 2 (not 6) spaces for indentation.
Tab detected.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
Tab detected.
end
Tab detected.
end
 
Tab detected.
def show
Tab detected.
Don't use parentheses around the condition of an `if`.
Space inside parentheses detected.
Don't use parentheses around a method call.
Use 2 (not 1) spaces for indentation.
Use a guard clause instead of wrapping the code inside a conditional expression.
if ( logged_in? )
Tab detected.
Use 2 (not 1) spaces for indentation.
@suspension = Suspension.find(params[:id])
Tab detected.
@alumn = Alumn.find_by_id(@suspension.alumn_id)
Tab detected.
@employee = Employee.find(@suspension.employee_id)
Tab detected.
end
Tab detected.
end
 
Method has too many lines. [17/10]
Cyclomatic complexity for create is too high. [4/3]
Assignment Branch Condition size for create is too high. [15.81/15]
Method `create` has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
SuspensionsController#create has approx 8 statements
Tab detected.
def create
Space inside parentheses detected.
Tab detected.
Space after keyword `if` is missing.
Use 2 (not 1) spaces for indentation.
if( is_principal? )
Tab detected.
Use 2 (not 1) spaces for indentation.
@suspension = @@alumn.suspensions.create(suspension_params)
Tab detected.
@suspension.employee_id = @current_user.id
Space inside parentheses detected.
Space after keyword `if` is missing.
Tab detected.
if( @suspension.save )
Tab detected.
Use 2 (not 1) spaces for indentation.
@alumn = Alumn.find_by_id(@suspension.alumn_id)
Space inside parentheses detected.
Tab detected.
Space after keyword `if` is missing.
if( @alumn.save )
Tab detected.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Use 2 (not 1) spaces for indentation.
flash[:success] = "Suspensão criada com sucesso"
Tab detected.
redirect_to alumn_path(@alumn)
Tab detected.
else
SuspensionsController#create calls 'render 'suspensions/new'' 2 times
Use 2 (not 1) spaces for indentation.
Tab detected.
render 'suspensions/new'
Tab detected.
end
Tab detected.
else
Use 2 (not 1) spaces for indentation.
Tab detected.
render 'suspensions/new'
Tab detected.
end
Tab detected.
else
Tab detected.
Use 2 (not 3) spaces for indentation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
Tab detected.
end
Tab detected.
end
 
Method has too many lines. [12/10]
Cyclomatic complexity for destroy is too high. [4/3]
Method `destroy` has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Tab detected.
def destroy
Space inside parentheses detected.
Space after keyword `if` is missing.
Tab detected.
Use 2 (not 1) spaces for indentation.
if( is_principal? )
Use 2 (not 1) spaces for indentation.
Tab detected.
@suspension = Suspension.find(params[:id])
Tab detected.
@alumn = Alumn.find_by_id(@suspension.alumn_id)
Space inside parentheses detected.
Tab detected.
Space after keyword `if` is missing.
if( @suspension.destroy )
Space after keyword `if` is missing.
Space inside parentheses detected.
Tab detected.
Use 2 (not 1) spaces for indentation.
if( @alumn.save )
Use 2 (not 1) spaces for indentation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Tab detected.
flash[:alert] = "Suspensão excluída com sucesso"
Tab detected.
redirect_to users_path
Tab detected.
end
Tab detected.
end
Tab detected.
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Use 2 (not 6) spaces for indentation.
Tab detected.
redirect_to "/errors/error_500"
Tab detected.
end
Tab detected.
end
 
Tab detected.
def edit
Tab detected.
Space after keyword `if` is missing.
Space inside parentheses detected.
Use 2 (not 1) spaces for indentation.
if( is_principal? )
Tab detected.
Use 2 (not 1) spaces for indentation.
@suspension = Suspension.find(params[:id])
Tab detected.
@alumn = Alumn.find_by_id(@suspension.alumn_id)
Tab detected.
else
Use 2 (not 6) spaces for indentation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Tab detected.
redirect_to "/errors/error_500"
Tab detected.
end
Tab detected.
end
 
Method has too many lines. [11/10]
Similar blocks of code found in 2 locations. Consider refactoring.
Tab detected.
def update
Space inside parentheses detected.
Space after keyword `if` is missing.
Use 2 (not 1) spaces for indentation.
Tab detected.
if( is_principal? )
Tab detected.
Use 2 (not 1) spaces for indentation.
@suspension = Suspension.find(params[:id])
Space inside parentheses detected.
Space after keyword `if` is missing.
Tab detected.
if( @suspension.update(suspension_params) )
Tab detected.
Use 2 (not 1) spaces for indentation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:notice] = "Suspensão alterada com sucesso"
Tab detected.
redirect_to suspension_path(@suspension)
Tab detected.
else
Use 2 (not 1) spaces for indentation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Tab detected.
render "suspensions/edit"
Tab detected.
end
Tab detected.
else
Tab detected.
Use 2 (not 6) spaces for indentation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
Tab detected.
end
Tab detected.
end
 
Keep a blank line before and after `private`.
Indent access modifiers like `private`.
Tab detected.
private
Tab detected.
def suspension_params
Use 2 (not 1) spaces for indentation.
Tab detected.
params.require(:suspension).permit(:title,
Align the parameters of a method call if they span more than one line.
:description,
Align the parameters of a method call if they span more than one line.
:quantity_days,
Align the parameters of a method call if they span more than one line.
:employee_id,
Align the parameters of a method call if they span more than one line.
:alumn_id,
Align the parameters of a method call if they span more than one line.
Tab detected.
:date_suspension)
Tab detected.
end
end