Class ApiKey
has 76 methods (exceeds 20 allowed). Consider refactoring. Open
class ApiKey < ActiveRecord::Base
include Carto::AuthTokenGenerator
include ::MessageBrokerHelper
File api_key.rb
has 535 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'securerandom'
require './lib/api_key_grants_validator'
require_dependency 'carto/errors'
require_dependency 'carto/helpers/auth_token_generator'
require_dependency 'carto/oauth_provider/scopes/scopes'
Method table_permissions_from_db
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
def table_permissions_from_db
query = %{
WITH permissions AS (
SELECT
table_schema,
Method setup_permissions
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def setup_permissions(permissions)
non_existent = []
errors = []
permissions.each do |api_key_permission|
next if api_key_permission.permissions.empty?
- 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 valid_default_public_key
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def valid_default_public_key
errors.add(:name, "must be #{NAME_DEFAULT_PUBLIC} for default public keys") unless name == NAME_DEFAULT_PUBLIC
errors.add(:grants, "must grant all apis") unless grants == [GRANTS_ALL_APIS]
errors.add(:token, "must be #{TOKEN_DEFAULT_PUBLIC} for default public keys") unless token == TOKEN_DEFAULT_PUBLIC
end
- 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 valid_master_key
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def valid_master_key
errors.add(:name, "must be #{NAME_MASTER} for master keys") unless name == NAME_MASTER
unless grants == MASTER_API_KEY_GRANTS
errors.add(:grants, "must grant all apis")
end
- 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"