activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Summary

Maintainability
F
3 days
Test Coverage

File schema_statements.rb has 741 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "active_support/core_ext/string/access"
require "openssl"

module ActiveRecord
  module ConnectionAdapters # :nodoc:

    Method type_to_sql has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

          def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) # :nodoc:
            type = type.to_sym if type
            if native = native_database_types[type]
              column_type_sql = (native.is_a?(Hash) ? native[:name] : native).dup
    
    

    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 create_table has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

          def create_table(table_name, id: :primary_key, primary_key: nil, force: nil, **options, &block)
            validate_create_table_options!(options)
            validate_table_length!(table_name) unless options[:_uses_legacy_table_name]
    
            if force && options.key?(:if_not_exists)

    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 index_name_for_remove has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

            def index_name_for_remove(table_name, column_name, options)
              return options[:name] if can_remove_index_by_name?(column_name, options)
    
              checks = []
    
    

    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 type_to_sql has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) # :nodoc:
            type = type.to_sym if type
            if native = native_database_types[type]
              column_type_sql = (native.is_a?(Hash) ? native[:name] : native).dup
    
    

      Method create_table has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def create_table(table_name, id: :primary_key, primary_key: nil, force: nil, **options, &block)
              validate_create_table_options!(options)
              validate_table_length!(table_name) unless options[:_uses_legacy_table_name]
      
              if force && options.key?(:if_not_exists)

        Method foreign_key_options has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def foreign_key_options(from_table, to_table, options) # :nodoc:
                options = options.dup
        
                if options[:primary_key].is_a?(Array)
                  options[:column] ||= options[:primary_key].map do |pk_column|

        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 bulk_change_table has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def bulk_change_table(table_name, operations) # :nodoc:
                sql_fragments = []
                non_combinable_operations = []
        
                operations.each do |command, args|

        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 remove_reference has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def remove_reference(table_name, ref_name, foreign_key: false, polymorphic: false, **options)
                conditional_options = options.slice(:if_exists, :if_not_exists)
        
                if foreign_key
                  reference_name = Base.pluralize_table_names ? ref_name.to_s.pluralize : ref_name

        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 index_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def index_name(table_name, options) # :nodoc:
                if Hash === options
                  if options[:column]
                    generate_index_name(table_name, options[:column])
                  elsif options[:name]

        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 rename_column_indexes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def rename_column_indexes(table_name, column_name, new_column_name)
                  column_name, new_column_name = column_name.to_s, new_column_name.to_s
                  indexes(table_name).each do |index|
                    next unless index.columns.include?(new_column_name)
                    old_columns = index.columns.dup

        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 column_exists? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def column_exists?(table_name, column_name, type = nil, **options)
                column_name = column_name.to_s
                checks = []
                checks << lambda { |c| c.name == column_name }
                checks << lambda { |c| c.type == type.to_sym rescue nil } if type

        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 build_create_join_table_definition(table_1, table_2, column_options: {}, **options) # :nodoc:
                join_table_name = find_join_table_name(table_1, table_2, options)
                column_options.reverse_merge!(null: false, index: false)
        
                t1_ref, t2_ref = [table_1, table_2].map { |t| reference_name_for_table(t) }
        activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb on lines 380..391

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

        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 create_join_table(table_1, table_2, column_options: {}, **options)
                join_table_name = find_join_table_name(table_1, table_2, options)
        
                column_options.reverse_merge!(null: false, index: false)
        
        
        activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb on lines 399..409

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

        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