ryanb/cancan

View on GitHub

Showing 13 of 13 total issues

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

  class ControllerResource # :nodoc:
    def self.add_before_filter(controller_class, method, *args)
      options = args.extract_options!
      resource_name = args.first
      before_filter_method = options.delete(:prepend) ? :prepend_before_filter : :before_filter
Severity: Minor
Found in lib/cancan/controller_resource.rb - About 5 hrs to fix

    Method matches_conditions_hash? has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def matches_conditions_hash?(subject, conditions = @conditions)
          if conditions.empty?
            true
          else
            if model_adapter(subject).override_conditions_hash_matching? subject, conditions
    Severity: Minor
    Found in lib/cancan/rule.rb - About 3 hrs 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_conditions has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

          def merge_conditions(sql, conditions_hash, behavior)
            if conditions_hash.blank?
              behavior ? true_sql : false_sql
            else
              conditions = sanitize_sql(conditions_hash)
    Severity: Minor
    Found in lib/cancan/model_adapters/active_record_adapter.rb - About 2 hrs 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 resource_base has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def resource_base
          if @options[:through]
            if parent_resource
              @options[:singleton] ? resource_class : parent_resource.send(@options[:through_association] || name.to_s.pluralize)
            elsif @options[:shallow]
    Severity: Minor
    Found in lib/cancan/controller_resource.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 tableized_conditions has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

          def tableized_conditions(conditions, model_class = @model_class)
            return conditions unless conditions.kind_of? Hash
            conditions.inject({}) do |result_hash, (name, value)|
              if value.kind_of? Hash
                value = value.dup
    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 check_authorization has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

          def check_authorization(options = {})
            self.after_filter(options.slice(:only, :except)) 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 matches_conditions_hash? has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def matches_conditions_hash?(subject, conditions = @conditions)
          if conditions.empty?
            true
          else
            if model_adapter(subject).override_conditions_hash_matching? subject, conditions
    Severity: Minor
    Found in lib/cancan/rule.rb - About 1 hr to fix

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

            def database_records
              if @rules.size == 0
                @model_class.where(:_id => {'$exists' => false, '$type' => 7}) # return no records in Mongoid
              elsif @rules.size == 1 && @rules[0].conditions.is_a?(Mongoid::Criteria)
                @rules[0].conditions
      Severity: Minor
      Found in lib/cancan/model_adapters/mongoid_adapter.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 find_resource has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def find_resource
            if @options[:singleton] && parent_resource.respond_to?(name)
              parent_resource.send(name)
            else
              if @options[:find_by]
      Severity: Minor
      Found in lib/cancan/controller_resource.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 merge_joins has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def merge_joins(base, add)
              add.each do |name, nested|
                if base[name].is_a?(Hash)
                  merge_joins(base[name], nested) unless nested.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 initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def initialize(base_behavior, action, subject, conditions, block)
      Severity: Minor
      Found in lib/cancan/rule.rb - About 35 mins to fix

        Method matches_conditions? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def matches_conditions?(action, subject, extra_args)
              if @match_all
                call_block_with_all(action, subject, extra_args)
              elsif @block && !subject_class?(subject)
                @block.call(subject, *extra_args)
        Severity: Minor
        Found in lib/cancan/rule.rb - About 35 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 database_records has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def database_records
                if override_scope
                  @model_class.scoped.merge(override_scope)
                elsif @model_class.respond_to?(:where) && @model_class.respond_to?(:joins)
                  mergeable_conditions = @rules.select {|rule| rule.unmergeable? }.blank?
        Severity: Minor
        Found in lib/cancan/model_adapters/active_record_adapter.rb - About 35 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