openjaf/cenit

View on GitHub
app/controllers/Oauth2AccountAuthorization.rb

Summary

Maintainability
C
1 day
Test Coverage

Method authorize_account has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
Open

  def authorize_account(soft = false)
    account_backup = Account.current
    user_backup = User.current
    Account.current = User.current = error_description = nil
    if (auth_header = request.headers['Authorization'])
Severity: Minor
Found in app/controllers/Oauth2AccountAuthorization.rb - About 1 day 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 authorize_account has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def authorize_account(soft = false)
    account_backup = Account.current
    user_backup = User.current
    Account.current = User.current = error_description = nil
    if (auth_header = request.headers['Authorization'])
Severity: Major
Found in app/controllers/Oauth2AccountAuthorization.rb - About 2 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                if (x_tenant_id = request.headers['X-Tenant-Id'])
                  if (x_tenant = Account.find_where(id: x_tenant_id).first)
                    Account.current = x_tenant
                  else
                    error_description = 'Invalid tenant'
    Severity: Major
    Found in app/controllers/Oauth2AccountAuthorization.rb - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                  if !error_description && (x_tenant_id || access_token.set_current_tenant!)
                    access_grant = Cenit::OauthAccessGrant.where(application_id: access_token.application_id).first
                    if access_grant
                      @oauth_scope = access_grant.oauth_scope
                    else
      Severity: Major
      Found in app/controllers/Oauth2AccountAuthorization.rb - About 45 mins to fix

        There are no issues that match your filters.

        Category
        Status