Showing 65 of 65 total issues
Class Application
has 44 methods (exceeds 20 allowed). Consider refactoring. Open
class Application
include Storable
# list of attributes to be fetched from storage
ATTRIBUTES = [:state, :plan_id, :plan_name, :redirect_url].freeze
Class Service
has 40 methods (exceeds 20 allowed). Consider refactoring. Open
class Service
include Storable
# list of attributes to be fetched from storage
ATTRIBUTES = %i[state referrer_filters_required backend_version provider_key].freeze
Method create_granularity_class
has 105 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_granularity_class(name)
Class.new do
include Instance
@name = name
Class Metric
has 28 methods (exceeds 20 allowed). Consider refactoring. Open
class Metric
module KeyHelpers
def key(service_id, id, attribute)
encode_key("metric/service_id:#{service_id}/id:#{id}/#{attribute}")
end
Method cfg_sentinels_handler
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def cfg_sentinels_handler(options)
# get role attr and remove from options
# will only be validated and included when sentinels are valid
role = options.delete :role
sentinels = options.delete :sentinels
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
def to_compact_s
s = year * 10000 + month * 100 + day
if sec != 0
s = s * 100000 + hour * 1000 + min * 10
MODS[sec] == 0 ? s + DIVS[sec] : s * 10 + sec
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 101.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
def new_to_compact_s
s = year * 10000 + month * 100 + day
if sec != 0
s = s * 100000 + hour * 1000 + min * 10
MODS[sec] == 0 ? s + DIVS[sec] : s * 10 + sec
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 101.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Class Status
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
class Status
# This is the default field we respond with when using OAuth redirects
# We only use 'redirect_uri' if a request sent such a param. See #397.
REDIRECT_URI_FIELD = 'redirect_url'.freeze
private_constant :REDIRECT_URI_FIELD
Class Memoizer
has 23 methods (exceeds 20 allowed). Consider refactoring. Open
class Memoizer
EXPIRE = 60
PURGE = 60
MAX_ENTRIES = 10000
ACTIVE = true
Class UsageReport
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class UsageReport
attr_reader :type, :period
def initialize(status, usage_limit)
@status = status
Method reschedule_failed_jobs
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def reschedule_failed_jobs
# There might be several callers trying to requeue failed jobs at the
# same time. We need to use a lock to avoid rescheduling the same
# failed job more than once.
key = dist_lock.lock
- 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 delete_stats_keys_with_val_0
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def delete_stats_keys_with_val_0(redis_conn, log_deleted_keys)
cursor = 0
loop do
with_retries do
- 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
Class Listener
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
class Listener < Sinatra::Base
disable :logging
enable :raise_errors
disable :show_exceptions
File listener.rb
has 255 lines of code (exceeds 250 allowed). Consider refactoring. Open
require '3scale/backend/version'
require '3scale/backend/cors'
require '3scale/backend/csp'
require 'json'
File application.rb
has 254 lines of code (exceeds 250 allowed). Consider refactoring. Open
module ThreeScale
module Backend
class Application
include Storable
Method normalize_non_empty_keys!
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def normalize_non_empty_keys!
AUTH_AUTHREP_COMMON_PARAMS.each do |p|
thisparam = params[p]
if !thisparam.nil?
if thisparam.class != String
- 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 do_api_method
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def do_api_method(method_name)
halt 403 if params.nil?
normalize_non_empty_keys!
- 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 to_compact_s
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def to_compact_s
s = year * 10000 + month * 100 + day
if sec != 0
s = s * 100000 + hour * 1000 + min * 10
MODS[sec] == 0 ? s + DIVS[sec] : s * 10 + sec
- 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 new_to_compact_s
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def new_to_compact_s
s = year * 10000 + month * 100 + day
if sec != 0
s = s * 100000 + hour * 1000 + min * 10
MODS[sec] == 0 ? s + DIVS[sec] : s * 10 + sec
- 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 start
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def start(job_queue)
loop do
break if @shutdown
jobs = fetch(wait: false, max: Worker::DEFAULT_MAX_CONCURRENT_JOBS)
- 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"