activerecord/lib/arel/visitors/to_sql.rb

Summary

Maintainability
F
6 days
Test Coverage

Class ToSql has 117 methods (exceeds 20 allowed). Consider refactoring.
Open

    class ToSql < Arel::Visitors::Visitor
      def initialize(connection)
        super()
        @connection = connection
      end
Severity: Major
Found in activerecord/lib/arel/visitors/to_sql.rb - About 2 days to fix

    File to_sql.rb has 851 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Arel # :nodoc: all
      module Visitors
        class UnsupportedVisitError < StandardError
          def initialize(object)
            super "Unsupported argument type: #{object.class.name}. Construct an Arel node instead."
    Severity: Major
    Found in activerecord/lib/arel/visitors/to_sql.rb - About 2 days to fix

      Method visit_Arel_Nodes_BoundSqlLiteral has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

              def visit_Arel_Nodes_BoundSqlLiteral(o, collector)
                collector.retryable = false
                bind_index = 0
      
                new_bind = lambda do |value|
      Severity: Minor
      Found in activerecord/lib/arel/visitors/to_sql.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 visit_Arel_Nodes_BoundSqlLiteral has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def visit_Arel_Nodes_BoundSqlLiteral(o, collector)
                collector.retryable = false
                bind_index = 0
      
                new_bind = lambda do |value|
      Severity: Minor
      Found in activerecord/lib/arel/visitors/to_sql.rb - About 1 hr to fix

        Method prepare_update_statement has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

                def prepare_update_statement(o)
                  if o.key && (has_limit_or_offset_or_orders?(o) || has_join_sources?(o))
                    stmt = o.clone
                    stmt.limit = nil
                    stmt.offset = nil
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.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 infix_value_with_paren has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

                def infix_value_with_paren(o, collector, value, suppress_parens = false)
                  collector << "( " unless suppress_parens
                  collector = if o.left.class == o.class
                    infix_value_with_paren(o.left, collector, value, true)
                  else
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.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 visit_Arel_Nodes_ValuesList has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

                def visit_Arel_Nodes_ValuesList(o, collector)
                  collector << "VALUES "
        
                  o.rows.each_with_index do |row, i|
                    collector << ", " unless i == 0
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.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 visit_Arel_Nodes_InsertStatement has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

                def visit_Arel_Nodes_InsertStatement(o, collector)
                  collector.retryable = false
                  collector << "INSERT INTO "
                  collector = visit o.relation, collector
        
        
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb - About 55 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 visit_Arel_Nodes_Window has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def visit_Arel_Nodes_Window(o, collector)
                  collector << "("
        
                  collect_nodes_for o.partitions, collector, "PARTITION BY "
        
        
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.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 visit_Arel_Nodes_SelectStatement has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def visit_Arel_Nodes_SelectStatement(o, collector)
                  if o.with
                    collector = visit o.with, collector
                    collector << " "
                  end
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.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 visit_Arel_Nodes_NotIn has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def visit_Arel_Nodes_NotIn(o, collector)
                  attr, values = o.left, o.right
        
                  if Array === values
                    collector.preparable = false
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.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 visit_Arel_Nodes_In has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def visit_Arel_Nodes_In(o, collector)
                  attr, values = o.left, o.right
        
                  if Array === values
                    collector.preparable = false
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.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 visit_Arel_Nodes_In(o, collector)
                  attr, values = o.left, o.right
        
                  if Array === values
                    collector.preparable = false
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb and 1 other location - About 55 mins to fix
        activerecord/lib/arel/visitors/to_sql.rb on lines 605..619

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

        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 visit_Arel_Nodes_NotIn(o, collector)
                  attr, values = o.left, o.right
        
                  if Array === values
                    collector.preparable = false
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb and 1 other location - About 55 mins to fix
        activerecord/lib/arel/visitors/to_sql.rb on lines 588..602

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

        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 4 locations. Consider refactoring.
        Open

                def visit_Arel_Nodes_GreaterThanOrEqual(o, collector)
                  case unboundable?(o.right)
                  when 1
                    return collector << "1=0"
                  when -1
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb and 3 other locations - About 30 mins to fix
        activerecord/lib/arel/visitors/to_sql.rb on lines 449..458
        activerecord/lib/arel/visitors/to_sql.rb on lines 461..470
        activerecord/lib/arel/visitors/to_sql.rb on lines 473..482

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

        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 4 locations. Consider refactoring.
        Open

                def visit_Arel_Nodes_GreaterThan(o, collector)
                  case unboundable?(o.right)
                  when 1
                    return collector << "1=0"
                  when -1
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb and 3 other locations - About 30 mins to fix
        activerecord/lib/arel/visitors/to_sql.rb on lines 437..446
        activerecord/lib/arel/visitors/to_sql.rb on lines 461..470
        activerecord/lib/arel/visitors/to_sql.rb on lines 473..482

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

        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 4 locations. Consider refactoring.
        Open

                def visit_Arel_Nodes_LessThan(o, collector)
                  case unboundable?(o.right)
                  when 1
                    return collector << "1=1"
                  when -1
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb and 3 other locations - About 30 mins to fix
        activerecord/lib/arel/visitors/to_sql.rb on lines 437..446
        activerecord/lib/arel/visitors/to_sql.rb on lines 449..458
        activerecord/lib/arel/visitors/to_sql.rb on lines 461..470

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

        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 4 locations. Consider refactoring.
        Open

                def visit_Arel_Nodes_LessThanOrEqual(o, collector)
                  case unboundable?(o.right)
                  when 1
                    return collector << "1=1"
                  when -1
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb and 3 other locations - About 30 mins to fix
        activerecord/lib/arel/visitors/to_sql.rb on lines 437..446
        activerecord/lib/arel/visitors/to_sql.rb on lines 449..458
        activerecord/lib/arel/visitors/to_sql.rb on lines 473..482

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

        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 visit_Arel_Nodes_Equality(o, collector)
                  right = o.right
        
                  return collector << "1=0" if unboundable?(right)
        
        
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb and 1 other location - About 25 mins to fix
        activerecord/lib/arel/visitors/to_sql.rb on lines 678..689

        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 visit_Arel_Nodes_NotEqual(o, collector)
                  right = o.right
        
                  return collector << "1=1" if unboundable?(right)
        
        
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb and 1 other location - About 25 mins to fix
        activerecord/lib/arel/visitors/to_sql.rb on lines 643..654

        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 visit_Arel_Nodes_DoesNotMatch(o, collector)
                  collector = visit o.left, collector
                  collector << " NOT LIKE "
                  collector = visit o.right, collector
                  if o.escape
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb and 1 other location - About 20 mins to fix
        activerecord/lib/arel/visitors/to_sql.rb on lines 485..493

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

        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 visit_Arel_Nodes_Matches(o, collector)
                  collector = visit o.left, collector
                  collector << " LIKE "
                  collector = visit o.right, collector
                  if o.escape
        Severity: Minor
        Found in activerecord/lib/arel/visitors/to_sql.rb and 1 other location - About 20 mins to fix
        activerecord/lib/arel/visitors/to_sql.rb on lines 497..505

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

        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