autotelik/datashift

View on GitHub
lib/datashift/populators/populator.rb

Summary

Maintainability
D
1 day
Test Coverage

Method insistent_belongs_to has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    def insistent_belongs_to(method_binding, record, value )

      operator = method_binding.operator

      klass = method_binding.model_method.operator_class
Severity: Minor
Found in lib/datashift/populators/populator.rb - About 3 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 assign has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    def assign(method_binding, record)

      model_method = method_binding.model_method

      operator = model_method.operator
Severity: Minor
Found in lib/datashift/populators/populator.rb - About 3 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

Assignment Branch Condition size for assign is too high. [68.33/60]
Open

    def assign(method_binding, record)

      model_method = method_binding.model_method

      operator = model_method.operator

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method prepare_data has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    def prepare_data(method_binding, data)

      raise NilDataSuppliedError, 'No method_binding supplied for prepare_data' unless method_binding

      @original_data = data
Severity: Minor
Found in lib/datashift/populators/populator.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

Perceived complexity for prepare_data is too high. [18/15]
Open

    def prepare_data(method_binding, data)

      raise NilDataSuppliedError, 'No method_binding supplied for prepare_data' unless method_binding

      @original_data = data

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Perceived complexity for assign is too high. [17/15]
Open

    def assign(method_binding, record)

      model_method = method_binding.model_method

      operator = model_method.operator

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method assign has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def assign(method_binding, record)

      model_method = method_binding.model_method

      operator = model_method.operator
Severity: Minor
Found in lib/datashift/populators/populator.rb - About 1 hr to fix

    Method prepare_data has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def prepare_data(method_binding, data)
    
          raise NilDataSuppliedError, 'No method_binding supplied for prepare_data' unless method_binding
    
          @original_data = data
    Severity: Minor
    Found in lib/datashift/populators/populator.rb - About 1 hr to fix

      Method insistent_belongs_to has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def insistent_belongs_to(method_binding, record, value )
      
            operator = method_binding.operator
      
            klass = method_binding.model_method.operator_class
      Severity: Minor
      Found in lib/datashift/populators/populator.rb - About 1 hr to fix

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

            def assignment(record, value, model_method)
        
              operator = model_method.operator
              connection_adapter_column = model_method.connection_adapter_column
        
        
        Severity: Minor
        Found in lib/datashift/populators/populator.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

        TODO found
        Open

                  # TODO: - now we know this column is an enum set operator type to :enum to save this check in future
        Severity: Minor
        Found in lib/datashift/populators/populator.rb by fixme

        TODO found
        Open

                # TODO: - add find by operators from headers or configuration to  insistent_find_by_list
        Severity: Minor
        Found in lib/datashift/populators/populator.rb by fixme

        TODO found
        Open

              # TODO: - enable clients to register their own transformation methods and call them here
        Severity: Minor
        Found in lib/datashift/populators/populator.rb by fixme

        Line is too long. [149/140]
        Open

                  logger.debug("Assignment via [#{operator}] to [#{value}] (CAST TYPE [#{model_method.connection_adapter_column.type_cast(value).inspect}])")

        Use params_num.zero? instead of params_num == 0.
        Open

                  if(params_num == 0)

        This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

        The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

        The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

        Example: EnforcedStyle: predicate (default)

        # bad
        
        foo == 0
        0 > foo
        bar.baz > 0
        
        # good
        
        foo.zero?
        foo.negative?
        bar.baz.positive?

        Example: EnforcedStyle: comparison

        # bad
        
        foo.zero?
        foo.negative?
        bar.baz.positive?
        
        # good
        
        foo == 0
        0 > foo
        bar.baz > 0

        Useless assignment to variable - klass.
        Open

              klass = model_method.klass

        This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

        assigned but unused variable - foo

        Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

        Example:

        # bad
        
        def some_method
          some_var = 1
          do_something
        end

        Example:

        # good
        
        def some_method
          some_var = 1
          do_something(some_var)
        end

        Use a guard clause instead of wrapping the code inside a conditional expression.
        Open

              if klass.respond_to?(operator.pluralize)

        Use a guard clause instead of wrapping the code inside a conditional expression

        Example:

        # bad
        def test
          if something
            work
          end
        end
        
        # good
        def test
          return unless something
          work
        end
        
        # also good
        def test
          work if something
        end
        
        # bad
        if something
          raise 'exception'
        else
          ok
        end
        
        # good
        raise 'exception' if something
        ok

        There are no issues that match your filters.

        Category
        Status