rubykube/barong

View on GitHub
lib/barong/authorize.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Class Authorize has 21 methods (exceeds 20 allowed). Consider refactoring.
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
Severity: Minor
Found in lib/barong/authorize.rb - About 2 hrs to fix

    Method validate_permissions! has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
    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) }
    Severity: Minor
    Found in lib/barong/authorize.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 api_key_owner has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
    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
    Severity: Minor
    Found in lib/barong/authorize.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

    There are no issues that match your filters.

    Category
    Status