CanCanCommunity/cancancan

View on GitHub

Showing 9 of 9 total issues

Class ControllerResource has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

  class ControllerResource # :nodoc:
    include ControllerResourceLoader

    def self.add_before_action(controller_class, method, *args)
      options = args.extract_options!
Severity: Minor
Found in lib/cancan/controller_resource.rb - About 2 hrs to fix

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

          def optimize_order!(rules)
            first_can_in_group = -1
            rules.each_with_index do |rule, i|
              (first_can_in_group = -1) && next unless rule.base_behavior
              (first_can_in_group = i) && next if first_can_in_group == -1
    Severity: Minor
    Found in lib/cancan/ability/rules.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 check_authorization has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

          def check_authorization(options = {})
            block = proc do |controller|
              next if controller.instance_variable_defined?(:@_authorized)
              next if options[:if] && !controller.send(options[:if])
              next if options[:unless] && controller.send(options[:unless])
    Severity: Minor
    Found in lib/cancan/controller_additions.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 merge_non_empty_conditions has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

          def merge_non_empty_conditions(behavior, conditions_hash, sql)
            conditions = sanitize_sql(conditions_hash)
            case sql
            when true_sql
              behavior ? true_sql : "not (#{conditions})"
    Severity: Minor
    Found in lib/cancan/model_adapters/active_record_adapter.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 sti_class? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.sti_class?(subject)
        return false unless defined?(ActiveRecord::Base)
        return false unless subject.respond_to?(:descends_from_active_record?)
        return false if subject == :all || subject.descends_from_active_record?
        return false unless subject < ActiveRecord::Base
    Severity: Minor
    Found in lib/cancan/sti_detector.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 deep_merge has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def deep_merge(base_hash, added_hash)
            added_hash.each do |key, value|
              if base_hash[key].is_a?(Hash)
                deep_merge(base_hash[key], value) unless value.empty?
              else
    Severity: Minor
    Found in lib/cancan/model_adapters/active_record_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 matching_class_check has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.matching_class_check(subject, sub, has_subclasses)
        matches = matches_class_or_is_related(subject, sub)
        if has_subclasses
          return matches unless StiDetector.sti_class?(sub)
    
    
    Severity: Minor
    Found in lib/cancan/class_matcher.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

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

      failure_message_when_negated do
        resource = args[1]
        if resource.instance_of?(Class)
          "expected not to be able to #{args.map(&:to_s).join(' ')}"
        else
    Severity: Minor
    Found in lib/cancan/matchers.rb and 1 other location - About 20 mins to fix
    lib/cancan/matchers.rb on lines 35..40

    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 27.

    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

      failure_message do
        resource = args[1]
        if resource.instance_of?(Class)
          "expected to be able to #{args.map(&:to_s).join(' ')}"
        else
    Severity: Minor
    Found in lib/cancan/matchers.rb and 1 other location - About 20 mins to fix
    lib/cancan/matchers.rb on lines 44..49

    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 27.

    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

    Severity
    Category
    Status
    Source
    Language