david-mccullars/activerecord-where-any-of

View on GitHub

Showing 4 of 4 total issues

Cyclomatic complexity for where_any_of is too high. [7/6]
Open

    def where_any_of(*conditions)
      # Rails 5 comes with an #or method for relations, so we can just use that
      # It is advised that once on Rails 5, this gem should be removed.

      # Do our best to preserve joins from the conditions into the outer relation

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 where_any_of has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def where_any_of(*conditions)
      # Rails 5 comes with an #or method for relations, so we can just use that
      # It is advised that once on Rails 5, this gem should be removed.

      # Do our best to preserve joins from the conditions into the outer relation
Severity: Minor
Found in lib/active_record/where-any-of-mixin-rails-5.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 where_any_of has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def where_any_of(*conditions)
      # Takes any number of scopes and OR them together
      # into a new scope which can be combined with other scopes
      bind_values = []
      conditions = conditions.map do |c|
Severity: Minor
Found in lib/active_record/where-any-of-mixin.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 __convert_string_wheres has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def __convert_string_wheres(wheres)
      wheres.map do |w|
        if w.is_a?(Arel::Nodes::Equality)
          w
        else
Severity: Minor
Found in lib/active_record/where-any-of-mixin.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

Severity
Category
Status
Source
Language