Showing 177 of 177 total issues
Method check
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def check
hydra = Typhoeus::Hydra.new
request = Typhoeus::Request.new(check_url, followlocation: true)
request.on_success do |response|
page = Nokogiri::XML response.body
- 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 execute_js
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def execute_js(js_function, incoming_events = [])
js_function = js_function == "check" ? "check" : "receive"
context = MiniRacer::Context.new
context.eval(setup_javascript)
Method handle_request
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def handle_request
user = User.find_by_id(params[:user_id])
if user
agent = user.agents.find_by_id(params[:agent_id])
if agent
Method open_ftp
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def open_ftp(uri)
ftp = Net::FTP.new
log "Connecting to #{uri.host}#{':%d' % uri.port if uri.port != uri.default_port}"
ftp.connect(uri.host, uri.port)
Consider simplifying this complex logical expression. Open
unless options['account_sid'].present? && options['auth_token'].present? && options['sender_cell'].present? && options['receiver_cell'].present? && options['expected_receive_period_in_days'].present? && options['receive_call'].present? && options['receive_text'].present?
errors.add(:base,
'account_sid, auth_token, sender_cell, receiver_cell, receive_text, receive_call and expected_receive_period_in_days are all required')
end
Method handle_data
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def handle_data(body, url, existing_payload)
# Beware, url may be a URI object, string or nil
doc = parse(body)
- 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_options
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def validate_options
if (spec = options['schedule']).present?
begin
cron = Fugit::Cron.new(spec) or raise ArgumentError
unless second_precision_enabled || (cron.seconds - [0, 15, 30, 45, 60]).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 grab_config_with_cmd!
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def grab_config_with_cmd!(cmd, opts = {})
config_data = capture(cmd, opts)
$config = {}
if config_data !~ /has no config vars/
config_data.split("\n").map do |line|
- 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 receive_web_request
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def receive_web_request(request)
params = request.params.except(:action, :controller, :agent_id, :user_id, :format)
method = request.method_symbol.to_s
headers = request.headers
- 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 create
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def create
attrs = agent_params
if agent = current_user.agents.find_by(id: params[:agent_id])
# POST /agents/:id/dry_run
if attrs.present?
- 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 configure_params
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def configure_params(params)
params[:chat_id] = interpolated['chat_id']
params[:disable_notification] =
interpolated['disable_notification'] if interpolated['disable_notification'].present?
if params.has_key?(:text)
- 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 set_table_sort
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def set_table_sort(sort_options)
valid_sorts = sort_options[:sorts] or raise ArgumentError.new("You must specify :sorts as an array of valid sort attributes.")
default = sort_options[:default] || { valid_sorts.first.to_sym => :desc }
if params[:sort].present?
- 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 convert_string
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def self.convert_string(string, leading_dollarsign_is_jsonpath=false)
if string == true || string == false
# there might be empty *_path attributes for boolean defaults
string
elsif string[0] == '$' && leading_dollarsign_is_jsonpath
- 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 send_message
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def send_message(options)
@groups = options[:groups]
@headline = options[:headline]
@body = options[:body]
- 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_compiled_matchers
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def apply_compiled_matchers(matchers, event, &block)
return yield if matchers.nil?
# event.payload.dup does not work; HashWithIndifferentAccess is
# a source of trouble here.
- 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
hideEventCreation() {
$(".event-related-region .select2-container").hide();
$(".event-related-region .cannot-create-events").show();
return $(".event-related-region").data("can-create-events", false);
}
- 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 52.
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
showEventCreation() {
$(".event-related-region .select2-container").show();
$(".event-related-region .cannot-create-events").hide();
return $(".event-related-region").data("can-create-events", true);
}
- 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 52.
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
Avoid deeply nested control flow statements. Open
if re && !re.names.include?(index)
errors.add(:base, "no named capture #{index.inspect} found in regexp for #{name.inspect})")
end
Method load_workers
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def load_workers
workers = {}
@@agents.each do |klass|
next if @options[:only] && !@options[:only].include?(klass)
next if @options[:except] && @options[:except].include?(klass)
- 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 deeply nested control flow statements. Open
case details['xpath']
when String
# ok
when nil
errors.add(:base,