lib/surveyor/helpers/surveyor_helper_methods.rb
Method response_for
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
Open
def response_for(response_set, question, answer = nil, response_group = nil)
return nil unless response_set && question && question.id
result = response_set.responses.detect{|r| (r.question_id == question.id) && (answer.blank? ? true : r.answer_id == answer.id) && (r.response_group.blank? ? true : r.response_group.to_i == response_group.to_i)}
result.blank? ? response_set.responses.build(:question_id => question.id, :response_group => response_group) : result
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 generate_pick_none_input_html
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def generate_pick_none_input_html(value, default_value, css_class, response_class, disabled, input_mask, input_mask_placeholder)
Method generate_pick_none_input_html
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def generate_pick_none_input_html(value, default_value, css_class, response_class, disabled, input_mask, input_mask_placeholder)
html = {}
html[:class] = [response_class,css_class].reject{ |c| c.blank? }
html[:value] = value.blank? ? default_value : value
html[:disabled] = disabled unless disabled.blank?
- 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"