kickstarter/rack-attack

View on GitHub

Class Attack has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

class Rack::Attack
  autoload :Cache,           'rack/attack/cache'
  autoload :PathNormalizer,  'rack/attack/path_normalizer'
  autoload :Check,           'rack/attack/check'
  autoload :Throttle,        'rack/attack/throttle'
Severity: Minor
Found in lib/rack/attack.rb - About 2 hrs to fix

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

          def [](req)
            discriminator = block[req]
            return false unless discriminator
    
            current_period = period.respond_to?(:call) ? period.call(req) : period
    Severity: Minor
    Found in lib/rack/attack/throttle.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 increment has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def increment(key, amount, options={})
              count = nil
              self.pipelined do
                count = self.incrby(key, amount)
                self.expire(key, options[:expires_in]) if options[:expires_in]
    Severity: Minor
    Found in lib/rack/attack/store_proxy/redis_store_proxy.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