Class SafeNavigation
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class SafeNavigation < Base
include NilMethods
include RangeHelp
extend AutoCorrector
extend TargetRubyVersion
Method unsafe_method_used?
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def unsafe_method_used?(method_chain, method)
return true if unsafe_method?(method)
method.each_ancestor(:send).any? do |ancestor|
break true unless config.for_cop('Lint/SafeNavigationChain')['Enabled']
- 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 add_safe_nav_to_all_methods_in_chain
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def add_safe_nav_to_all_methods_in_chain(corrector,
start_method,
method_chain)
start_method.each_ancestor do |ancestor|
break unless %i[send block].include?(ancestor.type)
- 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
return if method_chain.method?(:empty?)
Method check_node
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def check_node(node)
checked_variable, receiver, method_chain, method = extract_parts(node)
return if receiver != checked_variable || receiver.nil?
return if use_var_only_in_unless_modifier?(node, checked_variable)
return if chain_length(method_chain, method) > max_chain_length
- 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"