Showing 65 of 65 total issues
Method validate
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def validate(oauth, provider_key, report_usage, params, request_info)
Method store_key
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def store_key(client, cmd, key, value, expire_time = nil)
Method to_hash
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def self.to_hash(service_id, plan_id, metric_id, period, value)
Method update_utilization
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def update_utilization(service_id, app_id, max_utilization, max_record, timestamp)
Method aggregate_values
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def aggregate_values(value, timestamp, keys, cmd, client = storage)
Method delete!
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def delete!(redis_conns, log_deleted_keys: nil)
services = services_to_delete
logger.info("Going to delete the stats keys for these services: #{services.to_a}")
unless services.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 threescale_extensions
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.threescale_extensions(env, params = nil)
options = env['HTTP_3SCALE_OPTIONS'.freeze]
if options
::Rack::Utils.parse_nested_query(options).symbolize_names
else
- 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 fetch
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def fetch(wait: true, max: nil)
queue, encoded_jobs = wait ? wait_pop_from_queue : try_pop_from_queue(max)
return if !encoded_jobs || encoded_jobs.empty?
# filter_map to ignore `decode_job` errors causing it to return `nil`
- 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 clear_queue
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def clear_queue
fetcher = JobFetcher.new(fetch_timeout: 1)
worker = new_worker(fetcher)
queues = fetcher.instance_variable_get(:@queues)
redis = async? ? fetcher.instance_variable_get(:@redis) : dup_resque_redis
- 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_encoding?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def valid_encoding?
self.each do |v|
if v.is_a?(String) || v.is_a?(Array) || v.is_a?(Hash)
return false unless v.valid_encoding?
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 process_parents
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def process_parents(usage)
usage.inject(usage.dup) do |memo, (id, val)|
is_set_op = Usage.is_set?(val)
while (id = parent_id(id))
- 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_wrapper
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def perform_wrapper(args)
start_time = Time.now.getutc
status_ok, message = perform_logged(*args)
stats_mem = Memoizer.stats
end_time = Time.now.getutc
- 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 resolve_slave
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def resolve_slave
@sentinel_endpoints.each do |sentinel_endpoint|
client = Async::Redis::Client.new(sentinel_endpoint, protocol: Protocol::ExtendedRESP2.new(credentials: @sentinel_credentials))
begin
- 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 apply
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def apply
invalid_exception = RedirectURIInvalid
redirect_uri = if params.has_key? REDIRECT_URL
invalid_exception = RedirectURLInvalid
params[REDIRECT_URL]
- 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 6 (exceeds 5 allowed). Consider refactoring. Open
def self.start(global_options, options, args)
manifest = global_options[:manifest]
return unless manifest
argv = ['puma']
argv_add argv, options[:daemonize], '-d'
- 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 utilization
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def utilization(app_usage_reports)
max_utilization = -1.0
max_record = nil
max = proc do |item|
if item.max_value > 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"
Further reading
Method fix_date_cols
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def fix_date_cols(hash, period_val)
DATE_COLS.each do |date_col|
hash[date_col] = if date_col == 'year'
period_val.slice! 0, 4
else
- 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 apply
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def apply
if service.referrer_filters_required? && application.has_referrer_filters?
if application.referrer_filters.any? { |filter| matches?(filter, params[:referrer]) }
succeed!
else
- 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 parse_json_params
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def parse_json_params(params)
# Puma::NullIO (in v4.3.9) does not implement "closed?"
body_closed = if request.body.respond_to?(:closed?)
request.body.closed?
elsif request.body.respond_to?(:eof?)
- 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
get '/:id' do |service_id, id|
metric = Metric.load service_id, id
if metric
{ status: :found, metric: metric.to_hash }.to_json
else
- 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 28.
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