File visualizations_controller.rb
has 537 lines of code (exceeds 250 allowed). Consider refactoring. Open
require_relative '../../models/map/presenter'
require_relative '../carto/admin/user_table_public_map_adapter'
require_relative '../carto/admin/visualization_public_map_adapter'
require_relative '../carto/api/visualization_presenter'
require_relative '../carto/api/received_notification_presenter'
Method public_map
has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring. Open
def public_map
if current_user.nil? && !request.params[:redirected].present?
redirect_url = get_corrected_url_if_proceeds(for_table=false)
unless redirect_url.nil?
redirect_to redirect_url and return
- 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 VisualizationsController
has 43 methods (exceeds 20 allowed). Consider refactoring. Open
class Admin::VisualizationsController < Admin::AdminController
include CartoDB, VisualizationsControllerHelper
include Carto::FrameOptionsHelper
include Carto::UUIDHelper
Method public_table
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
def public_table
return(render_pretty_404) if @visualization.private?
if @visualization.derived?
if current_user.nil? || current_user.username != request.params[:user_domain]
- 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 get_corrected_url_if_proceeds
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def get_corrected_url_if_proceeds(for_table=true)
url = nil
return url if CartoDB.subdomainless_urls?
- 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 public_table
has 75 lines of code (exceeds 25 allowed). Consider refactoring. Open
def public_table
return(render_pretty_404) if @visualization.private?
if @visualization.derived?
if current_user.nil? || current_user.username != request.params[:user_domain]
Method public_map
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
def public_map
if current_user.nil? && !request.params[:redirected].present?
redirect_url = get_corrected_url_if_proceeds(for_table=false)
unless redirect_url.nil?
redirect_to redirect_url and return
Method show
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def show
table_action = request.original_fullpath =~ %r{/tables/}
unless current_user.present?
if table_action
return(redirect_to CartoDB.url(self, 'public_table_map', params: { id: request.params[: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 show_protected_public_map
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def show_protected_public_map
submitted_password = params.fetch(:password, nil)
return(render_pretty_404) unless @visualization.password_protected? and @visualization.has_password?
unless @visualization.password_valid?(submitted_password)
- 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 show_protected_embed_map
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def show_protected_embed_map
submitted_password = params.fetch(:password, nil)
return(render_pretty_404) unless @visualization.password_protected? and @visualization.has_password?
unless @visualization.password_valid?(submitted_password)
- 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 show
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def show
table_action = request.original_fullpath =~ %r{/tables/}
unless current_user.present?
if table_action
return(redirect_to CartoDB.url(self, 'public_table_map', params: { id: request.params[:id] }))
Method get_corrected_url_if_proceeds
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_corrected_url_if_proceeds(for_table=true)
url = nil
return url if CartoDB.subdomainless_urls?
Method show_protected_public_map
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def show_protected_public_map
submitted_password = params.fetch(:password, nil)
return(render_pretty_404) unless @visualization.password_protected? and @visualization.has_password?
unless @visualization.password_valid?(submitted_password)
Avoid deeply nested control flow statements. Open
if for_table
url = CartoDB.url(self, 'public_tables_show',
params: { id: "#{params[:user_domain]}.#{params[:id]}", redirected: true },
user: user)
else
Method embed_map_actual
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def embed_map_actual
return(embed_forbidden) if @visualization.private?
return(embed_protected) if @visualization.password_protected?
return(show_organization_embed_map) if org_user_has_map_permissions?(current_user, @visualization)
- 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 embed_map
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def embed_map
if request.format == 'text/javascript'
error_message = "/* Javascript embeds are deprecated, please use the html iframe instead */"
return render inline: error_message, status: 400
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
Avoid too many return
statements within this method. Open
return(redirect_to protocol: 'https://') if @visualization.is_privacy_private? \
Avoid too many return
statements within this method. Open
return redirect_to CartoDB.url(self, 'builder_visualization', params: { id: request.params[:id] },
user: current_user)
Avoid too many return
statements within this method. Open
return
Avoid too many return
statements within this method. Open
return render(file: 'public/static/show/index.html', layout: false)
Avoid too many return
statements within this method. Open
return redirect_to CartoDB.url(self, 'public_visualizations_public_map',
params: { id: request.params[:id], redirected: true })
Avoid too many return
statements within this method. Open
return(public_map_protected) if @visualization.password_protected?
Method get_visualization_and_table
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_visualization_and_table(table_id, schema, filter)
user = Carto::User.where(username: schema).first
# INFO: organization public visualizations
if user
visualization = get_priority_visualization(table_id, user_id: user.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
Similar blocks of code found in 2 locations. Consider refactoring. Open
def download_formats(table, format)
format.sql { send_data table.to_sql, data_for(table, 'zip', 'zip') }
format.kml { send_data table.to_kml, data_for(table, 'zip', 'kmz') }
format.csv { send_data table.to_csv, data_for(table, 'zip', 'zip') }
format.shp { send_data table.to_shp, data_for(table, 'octet-stream', 'zip') }
- 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 42.
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 table_and_schema_from_params
if params.fetch('id', nil) =~ /\./
@table_id, @schema = params.fetch('id').split('.').reverse
else
@table_id, @schema = [params.fetch('id', nil), nil]
- 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 31.
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