gregbeech/xenon

View on GitHub
xenon-routing/lib/xenon/routing/param_directives.rb

Summary

Maintainability
A
1 hr
Test Coverage

Cyclomatic complexity for convert_param_type is too high. [9/6]
Open

      def convert_param_type(value, type)
        if type == String then value
        elsif type == Symbol then value.to_sym
        elsif type == Bignum || type == Fixnum || type == Integer then Integer(value)
        elsif type == Float then Float(value)

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method convert_param_type has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

      def convert_param_type(value, type)
        if type == String then value
        elsif type == Symbol then value.to_sym
        elsif type == Bignum || type == Fixnum || type == Integer then Integer(value)
        elsif type == Float then Float(value)
Severity: Minor
Found in xenon-routing/lib/xenon/routing/param_directives.rb - About 55 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

Method params has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def params(*param_defs)
        param_hash do |hash|
          values = Array(param_defs).map do |param_def|
            if param_def.respond_to?(:has_key?)
              name, settings = param_def.each_pair.first
Severity: Minor
Found in xenon-routing/lib/xenon/routing/param_directives.rb - About 45 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

Useless assignment to variable - value.
Open

              value = convert_param_type(value, settings[:type]) if settings.has_key?(:type)

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

Ambiguous splat operator. Parenthesize the method arguments if it's surely a splat operator, or add a whitespace to the right of the * if it should be a multiplication.
Open

          yield *values

This cop checks for ambiguous operators in the first argument of a method invocation without parentheses.

Example:

# bad

# The `*` is interpreted as a splat operator but it could possibly be
# a `*` method invocation (i.e. `do_something.*(some_array)`).
do_something *some_array

Example:

# good

# With parentheses, there's no ambiguity.
do_something(*some_array)

Useless assignment to variable - value.
Open

              value = hash[param_def]

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

There are no issues that match your filters.

Category
Status