Showing 15 of 65 total issues
File users.rb
has 542 lines of code (exceeds 400 allowed). Consider refactoring. Open
module API
module V2
module Admin
# Admin functionality over users table
class Users < Grape::API
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
Method handle_message
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def handle_message(delivery_info, _metadata, payload)
exchange = @exchanges.select { |_, ex| ex[:name] == delivery_info[:exchange] }
exchange_id = exchange.keys.first.to_s
signer = exchange[exchange_id.to_sym][:signer]
Method authorize
has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring. Open
def authorize
@restrictions = Rails.cache.fetch('restrictions', expires_in: 5.minutes) { fetch_restrictions }
# whitelink path
unless params[:path] == 'api/v2/barong/identity/users/access'
- 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 seed_users
has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring. Open
def seed_users
logger.info "Seeding users"
seeds["users"].each do |seed|
logger.info "---"
- 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 perform
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def perform(user_id, identificator)
# user, that will be verified
@user = User.find(user_id)
# exact batch of the docs to be verified
docs = @user.documents.where(identificator: identificator)
Method perform
has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring. Open
def perform(params)
params = params.symbolize_keys
params.slice(:verification_id, :applicant_id, :verified, :verifications)
user = Profile.find_by(applicant_id: params[:applicant_id]).user
- 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
Consider simplifying this complex logical expression. Open
return false if (operator == :and && res.all?) || (operator == :or && res.any?) ||
(operator == :not && !res.all?)
Method seed_restrictions
has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring. Open
def seed_restrictions
logger.info "Seeding restrictions"
return logger.info "Restrictions seed is empty!" if seeds["restrictions"].empty?
seeds["restrictions"].each do |seed|
- 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 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) }
- 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 handle_message
has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring. Open
def handle_message(delivery_info, _metadata, payload)
exchange = @exchanges.select { |_, ex| ex[:name] == delivery_info[:exchange] }
exchange_id = exchange.keys.first.to_s
signer = exchange[exchange_id.to_sym][:signer]
- 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
Avoid too many return
statements within this method. Open
return Rails.root.join(value).tap { |p| path!(key, p) }
Avoid too many return
statements within this method. Open
if restriction = @restrictions[category]['country']&.find { |r| r[0]&.casecmp?(country) } then return restriction end
Avoid too many return
statements within this method. Open
return Regexp.new value
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
- 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"