Showing 421 of 434 total issues
Method accept_incoming?
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def accept_incoming?(email, raw_email_data)
# See if new responses are prevented
gatekeeper = ResponseGatekeeper.for(allow_new_responses_from, self)
# Take action if the message looks like spam
spam_checker = ResponseGatekeeper::SpamChecker.new
- 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 track_search_query
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def track_search_query
@query = params[:query_array]
# TODO: more hackery to make alternate formats still work with query_array
if /^(.*)\.json$/.match(@query)
- 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 move
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def move
editor = admin_current_user
if params[:commit] == 'Move request to user' && !params[:user_url_name].blank?
destination_user = User.find_by_url_name(params[:user_url_name])
- 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 prepare_environment
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def self.prepare_environment
return unless @@db_path.nil?
# barf if we can't figure out the environment
environment = (ENV['RAILS_ENV'] or Rails.env)
- 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 xapian_value
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def xapian_value(field, type = nil, index_translations = false)
if index_translations && respond_to?("translations")
if (type == :date) || (type == :boolean)
value = single_xapian_value(field, type = type)
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ((this.value === 'normal' || this.value === 'backpage') && ($('#info_request_described_state').val() === 'not_foi' || $('#info_request_described_state').val() === 'vexatious')) {
$(this).attr('title', 'The request will not be hidden unless you change the prominence.');
$(this).tooltip('show');
submit_button.attr('title', 'Warning! You are about to save this request without hiding it!');
submit_button.tooltip();
- 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 60.
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
if ((this.value === 'vexatious' || this.value === 'not_foi') && ($('#info_request_prominence').val() === 'normal' || $('#info_request_prominence').val() === 'backpage')) {
$('#info_request_prominence').attr('title', 'The request will not be hidden unless you change the prominence.');
$('#info_request_prominence').tooltip('show');
submit_button.attr('title', 'Warning! You are about to save this request without hiding it!');
submit_button.tooltip();
- 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 60.
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
Method play
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def play
session[:request_game] = Time.zone.now
@missing = InfoRequest.
where_old_unclassified.
Method log_overdue_event_type
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.log_overdue_event_type(event_type)
date_field = case event_type
when 'overdue'
'date_response_required_by'
when 'very_overdue'
Function load
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
that.load = function() {
var cardError = document.getElementById('card-errors');
// Sync initial state for terms checkbox and submit button
that.submit.setAttribute('disabled', 'true');
Method create_batch
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_batch
@info_request_batch =
InfoRequestBatch.find(params[:info_request_batch_id])
authorize! :update, @info_request_batch
Method generate_upload_url
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def generate_upload_url
if params[:incoming_message_id]
incoming_message = IncomingMessage.find(params[:incoming_message_id])
email = incoming_message.from_email
name = incoming_message.safe_from_name || @info_request.public_body.name
Method hidden_user_explanation
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def hidden_user_explanation
prominence_reason = render_to_string(
partial: "admin_request/hidden_user_explanation/#{params[:message]}",
formats: [:text],
locals: {
Method make_request_summary_file
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def make_request_summary_file(info_request)
done = false
@render_to_file = true
assign_variables_for_show_template(info_request)
if HTMLtoPDFConverter.exist?
Method import_values_from_csv_row
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def import_values_from_csv_row(row, line, name, options)
is_new = new_record?
edit_info = if is_new
{ action: "creating new authority",
comment: 'Created from spreadsheet' }
Method load_file
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.load_file(file_name)
is_gz = file_name.include?(".gz")
file_name_db = is_gz ? file_name.gsub(".gz", "") : file_name
modified = File.stat(file_name).mtime
Method phases
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.phases
[
{ capital_label: _('Awaiting response'),
label: _('awaiting response'),
scope: :awaiting_response,
Method bulk_destroy
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def bulk_destroy
if params[:commit] == "No"
redirect_to(admin_request_url(params[:request_id]))
end
Method lookup_query
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def lookup_query
@locale = AlaveteliLocalization.locale
AlaveteliLocalization.with_locale(@locale) do
@query = params[:query]
@query = nil if @query == ""
Method attempt_to_find_original_attachment_attributes
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def attempt_to_find_original_attachment_attributes(mail, body:, nested: false)
all_attributes = get_attachment_attributes(mail)
def calculate_hexdigest(body)
# ensure bodies have the same line endings and are encoded the same