CanCanCommunity/cancancan

View on GitHub

Showing 7 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

    Severity
    Category
    Status
    Source
    Language