lib/formtastic/inputs/base/collections.rb
Method collection_from_association
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
Open
def collection_from_association
if reflection
if reflection.respond_to?(:options)
raise PolymorphicInputWithoutCollectionError.new(
"A collection must be supplied for #{method} input. Collections cannot be guessed for polymorphic associations."
- 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
Consider simplifying this complex logical expression. Open
Open
return raw_collection if (raw_collection.instance_of?(Array) || raw_collection.instance_of?(Range)) &&
([Array, String].include?(raw_collection.first.class) || raw_collection.first.is_a?(Integer)) &&
!(options.include?(:member_label) || options.include?(:member_value))
Method collection
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
def collection
# Return if we have a plain string
return raw_collection if raw_collection.is_a?(String)
# Return if we have an Array of strings, integers or arrays
- 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"