app/controllers/Oauth2AccountAuthorization.rb
Method authorize_account
has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring. Open
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'])
- 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 authorize_account
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
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'])
Avoid deeply nested control flow statements. Open
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'
Avoid deeply nested control flow statements. Open
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