activerecord/lib/active_record/enum.rb

Summary

Maintainability
C
1 day
Test Coverage

Method _enum has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

      def _enum(name, values, prefix: nil, suffix: nil, scopes: true, instance_methods: true, validate: false, **options)
        assert_valid_enum_definition_values(values)
        # statuses = { }
        enum_values = ActiveSupport::HashWithIndifferentAccess.new
        name = name.to_s
Severity: Minor
Found in activerecord/lib/active_record/enum.rb - About 4 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

Method _enum has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def _enum(name, values, prefix: nil, suffix: nil, scopes: true, instance_methods: true, validate: false, **options)
        assert_valid_enum_definition_values(values)
        # statuses = { }
        enum_values = ActiveSupport::HashWithIndifferentAccess.new
        name = name.to_s
Severity: Minor
Found in activerecord/lib/active_record/enum.rb - About 1 hr to fix

    Method assert_valid_enum_definition_values has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

          def assert_valid_enum_definition_values(values)
            case values
            when Hash
              if values.empty?
                raise ArgumentError, "Enum values #{values} must not be empty."
    Severity: Minor
    Found in activerecord/lib/active_record/enum.rb - About 1 hr 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

    Method define_enum_methods has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

              def define_enum_methods(name, value_method_name, value, scopes, instance_methods)
    Severity: Minor
    Found in activerecord/lib/active_record/enum.rb - About 35 mins to fix

      Method detect_enum_conflict! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def detect_enum_conflict!(enum_name, method_name, klass_method = false)
              if klass_method && dangerous_class_method?(method_name)
                raise_conflict_error(enum_name, method_name, type: "class")
              elsif klass_method && method_defined_within?(method_name, Relation)
                raise_conflict_error(enum_name, method_name, type: "class", source: Relation.name)
      Severity: Minor
      Found in activerecord/lib/active_record/enum.rb - About 25 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