CartoDB/cartodb20

View on GitHub
services/user-mover/export_user.rb

Summary

Maintainability
F
3 days
Test Coverage

File export_user.rb has 540 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'pg'
require 'redis'
require 'yaml'
require 'optparse'
require 'json'
Severity: Major
Found in services/user-mover/export_user.rb - About 1 day to fix

    Method initialize has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

          def initialize(options)
            default_options = { metadata: true, data: true, split_user_schemas: true, path: '', set_banner: true }
            @options = default_options.merge(options)
    
            @start = Time.now
    Severity: Minor
    Found in services/user-mover/export_user.rb - About 5 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 initialize has 110 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def initialize(options)
            default_options = { metadata: true, data: true, split_user_schemas: true, path: '', set_banner: true }
            @options = default_options.merge(options)
    
            @start = Time.now
    Severity: Major
    Found in services/user-mover/export_user.rb - About 4 hrs to fix

      Class ExportJob has 32 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class ExportJob
            include Carto::Configuration
      
            attr_reader :logger, :json_file
      
      
      Severity: Minor
      Found in services/user-mover/export_user.rb - About 4 hrs to fix

        Method dump_related_data has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

              def dump_related_data(model, id, exclude = [])
                data = {}
                id = [id] if id.is_a?(Integer) || id.is_a?(String)
        
                # first dump this model
        Severity: Minor
        Found in services/user-mover/export_user.rb - About 2 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 dump_redis_keys has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

              def dump_redis_keys
                File.open(@options[:path] + "/user_#{@user_id}_metadata.redis", "wb") do |dump|
                  File.open(@options[:path] + "/user_#{@user_id}_metadata_undo.redis", "wb") do |undo|
                    REDIS_KEYS.each do |k, v|
                      dump.write gen_redis_proto("SELECT", v[:db])
        Severity: Minor
        Found in services/user-mover/export_user.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 dump_redis_keys has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def dump_redis_keys
                File.open(@options[:path] + "/user_#{@user_id}_metadata.redis", "wb") do |dump|
                  File.open(@options[:path] + "/user_#{@user_id}_metadata_undo.redis", "wb") do |undo|
                    REDIS_KEYS.each do |k, v|
                      dump.write gen_redis_proto("SELECT", v[:db])
        Severity: Minor
        Found in services/user-mover/export_user.rb - About 1 hr to fix

          Method dump_related_data has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def dump_related_data(model, id, exclude = [])
                  data = {}
                  id = [id] if id.is_a?(Integer) || id.is_a?(String)
          
                  # first dump this model
          Severity: Minor
          Found in services/user-mover/export_user.rb - About 1 hr to fix

            Method initialize has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                  def initialize(conn, database_host, database_name, path, filename, database_schema = nil, logger = default_logger)
            Severity: Major
            Found in services/user-mover/export_user.rb - About 50 mins to fix

              Method orphan_overview_tables has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                    def orphan_overview_tables
                      return @orphan_overviews if @orphan_overviews
                      # PG12_DEPRECATED checks if the table raster_columns exsits
                      raster_available = user_pg_conn.exec(%{
                        SELECT 1
              Severity: Minor
              Found in services/user-mover/export_user.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

              Method reflections_for_model has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                    def reflections_for_model(model, skip = [], parents = [])
                      result = {}
                      parents << model.table_name.to_sym
                      reflections = model.reflections
                      related = reflections.keys.select { |r| reflections[r].through_reflection == nil && !parents.include?(reflections[r].table_name.to_sym) }
              Severity: Minor
              Found in services/user-mover/export_user.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 user_pg_conn
                      @user_pg_conn ||= PGconn.connect(host: @database_host,
                                                       user: CartoDB::DataMover::Config[:dbuser],
                                                       dbname: @database_name,
                                                       port: CartoDB::DataMover::Config[:user_dbport],
              Severity: Minor
              Found in services/user-mover/export_user.rb and 1 other location - About 25 mins to fix
              services/user-mover/export_user.rb on lines 434..440

              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 30.

              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 user_pg_conn
                      @user_conn ||= PGconn.connect(host: @database_host,
                                                    user: CartoDB::DataMover::Config[:dbuser],
                                                    dbname: @database_name,
                                                    port: CartoDB::DataMover::Config[:user_dbport],
              Severity: Minor
              Found in services/user-mover/export_user.rb and 1 other location - About 25 mins to fix
              services/user-mover/export_user.rb on lines 62..68

              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 30.

              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