rom-rb/rom-sql

View on GitHub

Showing 31 of 31 total issues

Class Relation has 47 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Relation < ROM::Relation
      # Query API for SQL::Relation
      #
      # @api public
      module Reading
Severity: Minor
Found in lib/rom/sql/relation/reading.rb - About 6 hrs to fix

    Class Attribute has 31 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Attribute < ROM::Attribute
          include AttributeWrapping
          include AttributeAliasing
    
          OPERATORS = %i[>= <= > <].freeze
    Severity: Minor
    Found in lib/rom/sql/attribute.rb - About 3 hrs to fix

      Method alter_table has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

              def alter_table(diff)
                return if diff.meta?
      
                writer.migration do |connection|
                  connection.alter_table(diff.table_name) do
      Severity: Minor
      Found in lib/rom/sql/migration/runner.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

      File reading.rb has 278 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require "rom/support/inflector"
      require "rom/sql/join_dsl"
      
      module ROM
        module SQL
      Severity: Minor
      Found in lib/rom/sql/relation/reading.rb - About 2 hrs to fix

        Method __join__ has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

                def __join__(type, other, join_cond = EMPTY_HASH, opts = EMPTY_HASH, &block)
                  if other.is_a?(Symbol) || other.is_a?(ROM::Relation::Name)
                    if join_cond.equal?(EMPTY_HASH) && !block
                      assoc = associations[other]
                      assoc.join(type, self)
        Severity: Minor
        Found in lib/rom/sql/relation/reading.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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                LineSegment = Type("lseg") do
                  SQL::Types.define(Values::LineSegment) do
                    input do |segment|
                      "[(#{ segment.begin.x },#{ segment.begin.y }),"\
                      "(#{ segment.end.x },#{ segment.end.y })]"
        Severity: Major
        Found in lib/rom/sql/extensions/postgres/types/geometric.rb and 1 other location - About 1 hr to fix
        lib/rom/sql/extensions/postgres/types/geometric.rb on lines 77..88

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

        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

                Box = Type("box") do
                  SQL::Types.define(Values::Box) do
                    input do |box|
                      "((#{ box.upper_right.x },#{ box.upper_right.y }),"\
                      "(#{ box.lower_left.x },#{ box.lower_left.y }))"
        Severity: Major
        Found in lib/rom/sql/extensions/postgres/types/geometric.rb and 1 other location - About 1 hr to fix
        lib/rom/sql/extensions/postgres/types/geometric.rb on lines 93..104

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

        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

                  JSON = Type("json") do
                    casts = ::Hash.new(-> v { ::Sequel.pg_json(v) })
                    json_null = ::Sequel.pg_json_wrap(nil)
                    casts[JSONNullType] = -> _ { json_null }
                    casts[::NilClass] = -> _ { json_null }
        Severity: Major
        Found in lib/rom/sql/extensions/postgres/types/json.rb and 1 other location - About 1 hr to fix
        lib/rom/sql/extensions/postgres/types/json.rb on lines 63..76

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

        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

                  JSONB = Type("jsonb") do
                    casts = ::Hash.new(-> v { ::Sequel.pg_jsonb(v) })
                    jsonb_null = ::Sequel.pg_jsonb_wrap(nil)
                    casts[JSONNullType] = -> _ { jsonb_null }
                    casts[::NilClass] = -> _ { jsonb_null }
        Severity: Major
        Found in lib/rom/sql/extensions/postgres/types/json.rb and 1 other location - About 1 hr to fix
        lib/rom/sql/extensions/postgres/types/json.rb on lines 47..60

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

        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

        Method alter_table has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def alter_table(diff)
                  return if diff.meta?
        
                  writer.migration do |connection|
                    connection.alter_table(diff.table_name) do
        Severity: Minor
        Found in lib/rom/sql/migration/runner.rb - About 1 hr to fix

          Method range_read_type has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                  def self.range_read_type(name)
                    SQL::Types.Constructor(Values::Range) do |value|
                      pg_range =
                        if value.is_a?(Sequel::Postgres::PGRange)
                          value
          Severity: Minor
          Found in lib/rom/sql/extensions/postgres/types/range.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 restriction_methods has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                    def self.restriction_methods(schema)
                      mod = Module.new
          
                      methods = schema.indexes.each_with_object([]) do |index, generated|
                        next if index.partial?
          Severity: Minor
          Found in lib/rom/plugins/relation/sql/auto_restrictions.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 call has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                  def call(primary_key:, db_type:, type:, allow_null:, **rest)
                    if primary_key
                      map_pk_type(type, db_type, **rest)
                    else
                      mapped_type = map_type(type, db_type, **rest)
          Severity: Minor
          Found in lib/rom/sql/schema/type_builder.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 __join__ has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def __join__(type, other, join_cond = EMPTY_HASH, opts = EMPTY_HASH, &block)
                    if other.is_a?(Symbol) || other.is_a?(ROM::Relation::Name)
                      if join_cond.equal?(EMPTY_HASH) && !block
                        assoc = associations[other]
                        assoc.join(type, self)
          Severity: Minor
          Found in lib/rom/sql/relation/reading.rb - About 1 hr to fix

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

                    def coerce_conditions(conditions)
                      conditions.each_with_object({}) { |(k, v), h|
                        if k.is_a?(Symbol) && schema.canonical.key?(k)
                          type = schema.canonical[k]
                          h[k] = v.is_a?(Array) ? v.map { |e| type[e] } : type[v]
            Severity: Minor
            Found in lib/rom/sql/relation/reading.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 method_missing has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                  def method_missing(meth, *args, &block)
                    if schema.key?(meth)
                      schema[meth]
                    else
                      type = type(meth)
            Severity: Minor
            Found in lib/rom/sql/projection_dsl.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 associate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                      def associate(tuples, curried_parent = nil, assoc:, keys:, parent: curried_parent)
                        result_type = result
            
                        output_tuples =
                          case assoc
            Severity: Minor
            Found in lib/rom/sql/plugin/associates.rb - About 45 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 range has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                    def self.range(name, read_type)
                      Type(name) do
                        type = SQL::Types.Nominal(Values::Range).constructor do |range|
                          format("%s%s,%s%s",
                                 range.exclude_begin? ? :'(' : :'[',
            Severity: Minor
            Found in lib/rom/sql/extensions/postgres/types/range.rb - About 45 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 __join__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                    def __join__(type, other, join_cond = EMPTY_HASH, opts = EMPTY_HASH, &block)
            Severity: Minor
            Found in lib/rom/sql/relation/reading.rb - About 35 mins to fix

              Method each_batch has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                      def each_batch(size: 1000)
                        pks = schema.primary_key
              
                        if pks.size > 1
                          raise ArgumentError, "Composite primary keys are not supported yet"
              Severity: Minor
              Found in lib/rom/sql/relation/reading.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

              Severity
              Category
              Status
              Source
              Language