File request_controller.rb
has 600 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'zip'
class RequestController < ApplicationController
skip_before_action :html_response, only: [:show, :select_authorities]
Method new
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
def new
# All new requests are of normal_sort
unless params[:outgoing_message].nil?
params[:outgoing_message][:what_doing] = 'normal_sort'
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
Class RequestController
has 33 methods (exceeds 20 allowed). Consider refactoring. Open
class RequestController < ApplicationController
skip_before_action :html_response, only: [:show, :select_authorities]
before_action :check_read_only, only: [:new, :upload_response]
before_action :set_render_recaptcha, only: [ :new ]
Method new
has 104 lines of code (exceeds 25 allowed). Consider refactoring. Open
def new
# All new requests are of normal_sort
unless params[:outgoing_message].nil?
params[:outgoing_message][:what_doing] = 'normal_sort'
end
Method render_new_compose
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def render_new_compose
params[:info_request] = {} unless params[:info_request]
# Reconstruct the params
# first the public body (by URL name or 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 upload_response
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def upload_response
AlaveteliLocalization.with_locale(locale) do
@info_request = InfoRequest.not_embargoed.find_by_url_title!(params[:url_title])
@reason_params = {
- 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 upload_response
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
def upload_response
AlaveteliLocalization.with_locale(locale) do
@info_request = InfoRequest.not_embargoed.find_by_url_title!(params[:url_title])
@reason_params = {
Method render_new_compose
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
def render_new_compose
params[:info_request] = {} unless params[:info_request]
# Reconstruct the params
# first the public body (by URL name or id)
Method download_entire_request
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def download_entire_request
AlaveteliLocalization.with_locale(locale) do
@info_request = InfoRequest.find_by_url_title!(params[:url_title])
# Check for access and hide emargoed requests immediately, so that we
# don't leak any info to people who can't access them
- 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 assign_variables_for_show_template
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def assign_variables_for_show_template(info_request)
@info_request = info_request
@status = info_request.calculate_status
@old_unclassified =
info_request.is_old_unclassified? && authenticated?
Method show
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def show
medium_cache
AlaveteliLocalization.with_locale(locale) do
# Test for whole request being hidden
return render_hidden if cannot?(:read, @info_request)
Method make_request_zip
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def make_request_zip(info_request, file_path)
Zip::File.open(file_path, create: true) do |zipfile|
file_info = make_request_summary_file(info_request)
zipfile.get_output_stream(file_info[:filename]) { |f| f.write(file_info[:data]) }
message_index = 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 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 show
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def show
medium_cache
AlaveteliLocalization.with_locale(locale) do
# Test for whole request being hidden
return render_hidden if cannot?(:read, @info_request)
- 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 make_request_summary_file
has a Cognitive Complexity of 7 (exceeds 5 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?
- 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 too many return
statements within this method. Open
redirect_to frontpage_path and return
Avoid too many return
statements within this method. Open
handle_spam_subject(@info_request.user) && return
Avoid too many return
statements within this method. Open
return
Avoid too many return
statements within this method. Open
return
Avoid too many return
statements within this method. Open
return
Avoid too many return
statements within this method. Open
handle_blocked_ip(@info_request) && return
Avoid too many return
statements within this method. Open
return render_new_preview if params[:preview].to_i == 1
Avoid too many return
statements within this method. Open
return
Avoid too many return
statements within this method. Open
return
Avoid too many return
statements within this method. Open
return
Similar blocks of code found in 2 locations. Consider refactoring. Open
def handle_blocked_ip(info_request)
if send_exception_notifications?
msg = "Possible spam request (ip_in_blocklist) from " \
"User##{info_request.user_id}: #{user_ip} (#{country_from_ip})"
ExceptionNotifier.notify_exception(Exception.new(msg), env: request.env)
- 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 40.
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 3 locations. Consider refactoring. Open
def handle_spam_subject(user)
if send_exception_notifications?
e = Exception.new("Spam request from user #{ user.id }")
ExceptionNotifier.notify_exception(e, env: request.env)
end
- 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 33.
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