app/helpers/washout_builder_method_return_type_helper.rb
Method create_html_public_method_return_type
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def create_html_public_method_return_type(xml, pre, output)
if !output.nil? && !output[0].blank?
complex_class = output[0].find_complex_class_name
if WashoutBuilder::Type::BASIC_TYPES.include?(output[0].type)
xml.span('class' => 'blue') { |y| y << "#{output[0].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
Prefer to_s
over string interpolation. Open
Open
xml.span('class' => 'blue') { |y| y << "#{output[0].type}" }
- Read upRead up
- Exclude checks
This cop checks for strings that are just an interpolated expression.
Example:
# bad
"#{@var}"
# good
@var.to_s
# good if @var is already a String
@var
Use the return of the conditional for variable assignment and comparison. Open
Open
if output[0].multiplied
complex_return_type = "Array of #{real_class}"
else
complex_return_type = "#{real_class}"
end
- Exclude checks
Prefer to_s
over string interpolation. Open
Open
complex_return_type = "#{real_class}"
- Read upRead up
- Exclude checks
This cop checks for strings that are just an interpolated expression.
Example:
# bad
"#{@var}"
# good
@var.to_s
# good if @var is already a String
@var