lib/barong/authorize.rb
Class Authorize
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class Authorize
STATE_CHANGING_VERBS = %w[POST PUT PATCH DELETE TRACE].freeze
# Custom Error class to support error status and message
class AuthError < StandardError
attr_reader :code
Method validate_permissions!
has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring. Open
Open
def validate_permissions!(user)
# Caches Permission.all result to optimize
permissions = Rails.cache.fetch('permissions', expires_in: 5.minutes) { Permission.all.to_ary }
permissions.select! { |a| a.role == user.role && ( a.verb == @request.env['REQUEST_METHOD'] || a.verb == 'ALL' ) && @path.starts_with?(a.path) }
- Read upRead up
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 api_key_owner
has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring. Open
Open
def api_key_owner
api_key = APIKeysVerifier.new(api_key_params)
# validate that nonce is a positive integer
error!({ errors: ['authz.nonce_not_valid_timestamp'] }, 401) if api_key_params[:nonce].to_i <= 0
- Read upRead up
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"