File tasks_controller.rb
has 443 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'csv'
class TasksController < ApplicationController
DEFAULT_TASK_COUNT = 5
DEFAULT_TASK_NAME = 'New Task'
Class TasksController
has 37 methods (exceeds 20 allowed). Consider refactoring. Open
class TasksController < ApplicationController
DEFAULT_TASK_COUNT = 5
DEFAULT_TASK_NAME = 'New Task'
before_filter :check_if_user_has_projects, :only => [:new, :create]
Method billable
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def billable
@project = current_user.projects.find(params[:project_id]) if params[:project_id]
return render :json => {:billable => false} if @project and @project.no_billing?
return render :json => {:billable => false} if params[:service_id].to_i < 0
return render :json => {:billable => true} if params[:service_id].to_i == 0
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def create
@task.task_due_calculation(params[:task][:due_at], current_user)
@task.duration = TimeParser.parse_time(params[:task][:duration])
@task.duration = 0 if @task.duration.nil?
if @task.service_id == -1
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method update
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update
@task = AbstractTask.accessed_by(current_user).find_by(:id => params[:id])
if @task.nil?
flash[:error] = t('flash.error.not_exists_or_no_permission', model: TaskRecord.model_name.human)
redirect_from_last and return
Method create
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
@task.task_due_calculation(params[:task][:due_at], current_user)
@task.duration = TimeParser.parse_time(params[:task][:duration])
@task.duration = 0 if @task.duration.nil?
if @task.service_id == -1
Method update
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def update
@task = AbstractTask.accessed_by(current_user).find_by(:id => params[:id])
if @task.nil?
flash[:error] = t('flash.error.not_exists_or_no_permission', model: TaskRecord.model_name.human)
redirect_from_last and return
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method auto_complete_for_resource_name
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def auto_complete_for_resource_name
return unless current_user.use_resources?
search = params[:term]
search = search.split(',').last if search
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return render :json => {:billable => false}
Method users_to_notify_popup
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def users_to_notify_popup
# anyone already attached to the task should be removed
excluded_ids = params[:watcher_ids].blank? ? 0 : params[:watcher_ids]
@users = current_user.customer ? current_user.customer.users.active.where("id NOT IN (#{excluded_ids})").order('name').limit(50) : []
@task = AbstractTask.accessed_by(current_user).find_by(:id => params[:id])
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method get_default_watchers
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_default_watchers
@task = create_entity
unless params[:id].blank?
@task = AbstractTask.accessed_by(current_user).find_by(:id => params[:id])
end
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method change_task_weight
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def change_task_weight
@user = current_user
if current_user.admin? and params[:user_id]
@user = current_user.company.users.find(params[:user_id])
end
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"