Showing 9 of 19 total issues
Method build_leave_time_usages
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def build_leave_time_usages
ActiveRecord::Base.transaction do
validate_application_covered_by_leave_time_interval
@available_leave_times.each do |lt|
- 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
Class BaseController
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
class BaseController < ApplicationController
before_action :set_actions
helper_method :current_collection, :current_object
load_and_authorize_resource
Method build_monthly_leave_types
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def build_monthly_leave_types(leave_type, config, prebuild, build_by_assign_date = false)
quota = extract_quota(config, @user, prebuild: prebuild)
if build_by_assign_date
date = @user.assign_date >= @user.join_date ? @user.assign_date : @user.join_date
while date <= Time.zone.now.to_date
- 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 join_date_based_by_assign_date
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def join_date_based_by_assign_date(leave_type, quota)
if @user.assign_date < @user.join_date
date = @user.join_date
expiration_date = date.next_year - 1.day
else
- 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 validate_application_covered_by_leave_time_interval
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def validate_application_covered_by_leave_time_interval
include_start_time = include_end_time = false
@available_leave_times.each do |lt|
include_start_time = true if lt.cover?(@leave_hours_by_date.keys.first) # leave_time start_date 跟 date 相同會不會 cover 到
include_end_time = true if lt.cover?(@leave_hours_by_date.keys.last)
- 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_from_duration_num
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def get_from_duration_num(duration_num)
found_at = @ranges.index do |pair|
(pair[0].present? ? (duration_num >= pair[0]) : true) &&
(pair[1].present? ? (duration_num <= pair[1]) : true)
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 build_special_leave_time_usages
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def build_special_leave_time_usages
return unless self.special_type?
leave_applications = User.find(self.user_id).leave_applications.where(leave_type: self.leave_type)
leave_applications.each do |la|
if la.leave_time_usages.empty? and la.hours <= la.available_leave_times.pluck(:usable_hours).sum
- 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 a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def update
if current_object.canceled?
action_fail t('warnings.not_cancellable'), :edit
else
current_object.assign_attributes(resource_params)
- 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 after_update
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def after_update(record)
create_leave_time_usages(record) if record.aasm_event?(:revise)
FlowdockService.new(leave_application: record).send_update_notification(record.aasm.to_state) if Rails.env.production?
UserMailer.reply_leave_applicaiton_email(record).deliver_later if record.aasm_event?(:approve) or record.aasm_event?(:reject)
InformationMailer.cancel_application(record).deliver_later if record.aasm_event?(:cancel) && Rails.env.production?
- 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"