lib/field_mapper/standard/field.rb
Class Field
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class Field
include FieldMapper::Marshaller
attr_reader(
:name,
Method cast_value
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
def cast_value(type, value, as_single_value: false)
return nil if value.nil?
case type.name
when "String" then return string(value)
when "FieldMapper::Types::Boolean" then return boolean(value)
- 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
Open
return cast_value(type.type, value) if as_single_value
Avoid too many return
statements within this method. Open
Open
return plat_instance_list(type, value) if type.plat_list?
Avoid too many return
statements within this method. Open
Open
when "Money" then return money(value)
Avoid too many return
statements within this method. Open
Open
when "Float" then return value.to_f
Avoid too many return
statements within this method. Open
Open
when "FieldMapper::Types::Plat" then return plat_instance(type, value)
Avoid too many return
statements within this method. Open
Open
return type.type.new(unmarshal(value)) if value.is_a?(String)
Avoid too many return
statements within this method. Open
Open
when "Integer" then return value.to_i
Method plat_instance
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def plat_instance(type, value)
return value if value.is_a?(FieldMapper::Standard::Plat)
return value if value.is_a?(Numeric)
return value.to_i if value.is_a?(String) && value =~ /\A\d+\z/
return type.type.new(value) if value.is_a?(Hash)
- 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"