lib/react/component/class_methods.rb
Method define_state_methods
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
Open
def define_state_methods(this, name, from = nil, &block)
this.define_method("#{name}") do
self.class.deprecation_warning "Direct access to state `#{name}`. Use `state.#{name}` instead." if from.nil? || from == this
State.get_state(from || self, name)
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 define_state_methods
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def define_state_methods(this, name, from = nil, &block)
this.define_method("#{name}") do
self.class.deprecation_warning "Direct access to state `#{name}`. Use `state.#{name}` instead." if from.nil? || from == this
State.get_state(from || self, name)
end
Consider simplifying this complex logical expression. Open
Open
if args.count > 0
yield name, State.get_state(from || self, name), args[0] if block && block.arity > 0
current_value = State.get_state(from || self, name)
State.set_state(from || self, name, args[0])
current_value
Method define_state
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def define_state(*states, &block)
default_initial_value = (block && block.arity == 0) ? yield : nil
states_hash = (states.last.is_a?(Hash)) ? states.pop : {}
states.each { |name| states_hash[name] = default_initial_value }
(self.initial_state ||= {}).merge! states_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"