Class has too many lines. [266/250] Open
class ValidVoucher < ActiveRecord::Base
# Capacity is infinite if it is left blank
INFINITE = 100_000
- Read upRead up
- Exclude checks
This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Class ValidVoucher
has 34 methods (exceeds 20 allowed). Consider refactoring. Open
class ValidVoucher < ActiveRecord::Base
# Capacity is infinite if it is left blank
INFINITE = 100_000
File valid_voucher.rb
has 268 lines of code (exceeds 250 allowed). Consider refactoring. Open
class ValidVoucher < ActiveRecord::Base
# Capacity is infinite if it is left blank
INFINITE = 100_000
Cyclomatic complexity for check_dates is too high. [7/6] Open
def check_dates
return if start_sales.blank? || end_sales.blank? || vouchertype.nil?
errors.add(:base,"Start sales time cannot be later than end sales time") and return if start_sales > end_sales
vt = self.vouchertype
if self.end_sales > (end_of_season = Time.current.at_end_of_season(vt.season))
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Method seats_of_type_remaining
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def seats_of_type_remaining
unless showdate
self.explanation = "No limit"
return INFINITE
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 display_min_and_max_sales_per_txn
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def display_min_and_max_sales_per_txn
if min_sales_per_txn == 1
max_sales_per_txn == INFINITE ? '' : "(max #{max_sales_per_txn} per order)"
else # minimum order
case max_sales_per_txn
- 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
Useless assignment to variable - showdate
. Open
v.reserve_for(showdate, customer) if (showdate = v.unique_showdate)
- Read upRead up
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Useless assignment to variable - remain
. Open
remain = [remain, 0].max # make sure it's positive
- Read upRead up
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end