lowjoel/cancancan-squeel

View on GitHub

Showing 11 of 11 total issues

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

  def build_expression_from_rule(squeel, rule)
    if rule.conditions.empty?
      [rule.base_behavior ? ALWAYS_TRUE : ALWAYS_FALSE, []]
    else
      comparator = rule.base_behavior ? :== : :!=
Severity: Minor
Found in lib/cancancan/squeel/squeel_adapter.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

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

  def build_expression_node(node, model_class, comparator, conditions, root = false)
Severity: Minor
Found in lib/cancancan/squeel/expression_builder.rb - About 35 mins to fix

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

      def build_association_comparison_node(node, model_class, key, comparator, value)
    Severity: Minor
    Found in lib/cancancan/squeel/expression_builder.rb - About 35 mins to fix

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

        def combine_squeel_expressions(left_expression, left_expression_joins, operator,
                                       right_expression, right_expression_joins)
      Severity: Minor
      Found in lib/cancancan/squeel/expression_combinator.rb - About 35 mins to fix

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

          def build_scalar_comparison_node(node, model_class, key, comparator, value)
        Severity: Minor
        Found in lib/cancancan/squeel/expression_builder.rb - About 35 mins to fix

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

            def build_comparison_node(node, model_class, key, comparator, value)
          Severity: Minor
          Found in lib/cancancan/squeel/expression_builder.rb - About 35 mins to fix

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              def disjunction_expressions(left_expression, left_expression_joins, right_expression,
                                          right_expression_joins)
                if left_expression == ALWAYS_TRUE || right_expression == ALWAYS_TRUE
                  [ALWAYS_TRUE, []]
                elsif left_expression == ALWAYS_FALSE
            Severity: Minor
            Found in lib/cancancan/squeel/expression_combinator.rb and 1 other location - About 35 mins to fix
            lib/cancancan/squeel/expression_combinator.rb on lines 44..54

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 34.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              def conjunction_expressions(left_expression, left_expression_joins, right_expression,
                                          right_expression_joins)
                if left_expression == ALWAYS_FALSE || right_expression == ALWAYS_FALSE
                  [ALWAYS_FALSE, []]
                elsif left_expression == ALWAYS_TRUE
            Severity: Minor
            Found in lib/cancancan/squeel/expression_combinator.rb and 1 other location - About 35 mins to fix
            lib/cancancan/squeel/expression_combinator.rb on lines 68..78

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 34.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              def comparator_for_inclusive_range(comparator, value)
                case comparator
                when :== then [:&, [[:>=, value.first], [:<=, value.last]]]
                when :!= then [:|, [[:<, value.first], [:>, value.last]]]
            Severity: Minor
            Found in lib/cancancan/squeel/attribute_mapper.rb and 1 other location - About 30 mins to fix
            lib/cancancan/squeel/attribute_mapper.rb on lines 112..115

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              def comparator_for_exclusive_range(comparator, value)
                case comparator
                when :== then [:&, [[:>=, value.first], [:<, value.last]]]
                when :!= then [:|, [[:<, value.first], [:>=, value.last]]]
            Severity: Minor
            Found in lib/cancancan/squeel/attribute_mapper.rb and 1 other location - About 30 mins to fix
            lib/cancancan/squeel/attribute_mapper.rb on lines 125..128

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

              def build_expression_node(node, model_class, comparator, conditions, root = false)
                conditions.reduce([nil, []]) do |(left_expression, joins), (key, value)|
                  comparison_node, node_joins = build_comparison_node(root ? node : node.dup, model_class,
                                                                      key, comparator, value)
                  if left_expression
            Severity: Minor
            Found in lib/cancancan/squeel/expression_builder.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