Showing 4 of 6 total issues
Method classy_enum_attr
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def classy_enum_attr(attribute, options={})
enum = (options[:class_name] || options[:enum] || attribute).to_s.camelize.constantize
allow_blank = options[:allow_blank] || false
allow_nil = options[:allow_nil] || false
default = ClassyEnum._normalize_default(options[:default], enum)
- 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 classy_enum_attr
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def classy_enum_attr(attribute, options={})
enum = (options[:class_name] || options[:enum] || attribute).to_s.camelize.constantize
allow_blank = options[:allow_blank] || false
allow_nil = options[:allow_nil] || false
default = ClassyEnum._normalize_default(options[:default], enum)
Method _normalize_value
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self._normalize_value(value, default=nil, allow_blank=false) # :nodoc:
if value.class == Class && value < ClassyEnum::Base
value = value.new.to_s
elsif value.present?
value = value.to_s
- 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 _normalize_default
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self._normalize_default(value, enum_class) # :nodoc:
if value.present?
if value.is_a? Proc
value = value.call(enum_class)
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"