formtastic/formtastic

View on GitHub
lib/formtastic/inputs/base/collections.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Method collection_from_association has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

        def collection_from_association
          if reflection
            if reflection.respond_to?(:options)
              raise PolymorphicInputWithoutCollectionError.new(
                        "A collection must be supplied for #{method} input. Collections cannot be guessed for polymorphic associations."
Severity: Minor
Found in lib/formtastic/inputs/base/collections.rb - About 2 hrs to fix

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

Consider simplifying this complex logical expression.
Open

          return raw_collection if (raw_collection.instance_of?(Array) || raw_collection.instance_of?(Range)) &&
                               ([Array, String].include?(raw_collection.first.class) || raw_collection.first.is_a?(Integer)) &&
                               !(options.include?(:member_label) || options.include?(:member_value))
Severity: Major
Found in lib/formtastic/inputs/base/collections.rb - About 40 mins to fix

    Method collection has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

            def collection
              # Return if we have a plain string
              return raw_collection if raw_collection.is_a?(String)
    
              # Return if we have an Array of strings, integers or arrays
    Severity: Minor
    Found in lib/formtastic/inputs/base/collections.rb - About 35 mins to fix

    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

    There are no issues that match your filters.

    Category
    Status