CartoDB/cartodb20

View on GitHub
app/controllers/admin/visualizations_controller.rb

Summary

Maintainability
F
6 days
Test Coverage

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'
Severity: Major
Found in app/controllers/admin/visualizations_controller.rb - About 1 day to fix

    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
    Severity: Minor
    Found in app/controllers/admin/visualizations_controller.rb - About 6 hrs to fix

    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
    
    
    Severity: Minor
    Found in app/controllers/admin/visualizations_controller.rb - About 5 hrs to fix

      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]
      Severity: Minor
      Found in app/controllers/admin/visualizations_controller.rb - About 4 hrs to fix

      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?
      
      
      Severity: Minor
      Found in app/controllers/admin/visualizations_controller.rb - About 3 hrs to fix

      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]
      Severity: Major
      Found in app/controllers/admin/visualizations_controller.rb - About 3 hrs to fix

        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
        Severity: Major
        Found in app/controllers/admin/visualizations_controller.rb - About 2 hrs to fix

          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] }))
          Severity: Minor
          Found in app/controllers/admin/visualizations_controller.rb - About 1 hr to fix

          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)
          Severity: Minor
          Found in app/controllers/admin/visualizations_controller.rb - About 1 hr to fix

          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)
          Severity: Minor
          Found in app/controllers/admin/visualizations_controller.rb - About 1 hr to fix

          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] }))
          Severity: Minor
          Found in app/controllers/admin/visualizations_controller.rb - About 1 hr to fix

            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?
            
            
            Severity: Minor
            Found in app/controllers/admin/visualizations_controller.rb - About 1 hr to fix

              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)
              Severity: Minor
              Found in app/controllers/admin/visualizations_controller.rb - About 1 hr to fix

                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
                Severity: Major
                Found in app/controllers/admin/visualizations_controller.rb - About 45 mins to fix

                  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)
                  
                  
                  Severity: Minor
                  Found in app/controllers/admin/visualizations_controller.rb - About 35 mins to fix

                  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
                  Severity: Minor
                  Found in app/controllers/admin/visualizations_controller.rb - About 35 mins to fix

                  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? \
                  Severity: Major
                  Found in app/controllers/admin/visualizations_controller.rb - About 30 mins to fix

                    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)
                    Severity: Major
                    Found in app/controllers/admin/visualizations_controller.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                            return
                      Severity: Major
                      Found in app/controllers/admin/visualizations_controller.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                              return render(file: 'public/static/show/index.html', layout: false)
                        Severity: Major
                        Found in app/controllers/admin/visualizations_controller.rb - About 30 mins to fix

                          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 })
                          Severity: Major
                          Found in app/controllers/admin/visualizations_controller.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                return(public_map_protected) if @visualization.password_protected?
                            Severity: Major
                            Found in app/controllers/admin/visualizations_controller.rb - About 30 mins to fix

                              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)
                              Severity: Minor
                              Found in app/controllers/admin/visualizations_controller.rb - About 25 mins to fix

                              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') }
                              Severity: Minor
                              Found in app/controllers/admin/visualizations_controller.rb and 1 other location - About 50 mins to fix
                              app/controllers/admin/tables_controller.rb on lines 52..56

                              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

                              Further Reading

                              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]
                              Severity: Minor
                              Found in app/controllers/admin/visualizations_controller.rb and 1 other location - About 25 mins to fix
                              app/controllers/carto/api/visualizations_controller.rb on lines 400..405

                              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

                              Further Reading

                              There are no issues that match your filters.

                              Category
                              Status