kaspernj/baza

View on GitHub

Showing 177 of 177 total issues

Method initialize has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def initialize(db)
    @db = db
    @conn = @db.opts.fetch(:conn)

    raise "No conn given" unless @conn
Severity: Major
Found in lib/baza/driver/active_record.rb - About 2 hrs to fix

    Method list has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      def list(database: nil, name: nil)
        ret = [] unless block_given?
    
        where_args = {}
        where_args["TABLE_NAME"] = name if name
    Severity: Minor
    Found in lib/baza/driver/mysql/tables.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 type has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def type
        unless @type
          if (match = @data.fetch(:type).match(/^([A-z]+)$/))
            @maxlength = false
            type = match[0].downcase.to_sym
    Severity: Minor
    Found in lib/baza/driver/sqlite3/column.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 add_order_sql has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def add_order_sql
        return if @args.nil?
    
        if @args[:orderby]
          @sql << " ORDER BY"
    Severity: Minor
    Found in lib/baza/commands/select.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 initialize has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def initialize(args)
        @args = {}
        args.each do |key, value|
          @args[key.to_sym] = value
        end
    Severity: Minor
    Found in lib/baza/row.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 execute has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def execute
        sql = ""
    
        @io.each_line do |line|
          next if line.strip.blank?
    Severity: Minor
    Found in lib/baza/commands/importer.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 select_sql has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def select_sql
        sql = "SELECT"
    
        if @count
          sql << " COUNT(*) AS count"
    Severity: Minor
    Found in lib/baza/sql_queries/select.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 clone has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def clone(newname, args = {})
        raise "Invalid name." if newname.to_s.strip.empty?
    
        sql = "CREATE TABLE #{@db.quote_table(newname)} ("
        first = true
    Severity: Minor
    Found in lib/baza/driver/mysql/table.rb - About 1 hr to fix

      Method change has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def change(data)
          newdata = data.clone
      
          newdata[:name] = name unless newdata.key?(:name)
          newdata[:type] = type unless newdata.key?(:type)
      Severity: Minor
      Found in lib/baza/driver/mysql/column.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 indexes has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def indexes
          @db.indexes
          ret = [] unless block_given?
      
          @db.query("PRAGMA index_list(#{@db.quote_table(name)})") do |d_indexes|
      Severity: Minor
      Found in lib/baza/driver/sqlite3/table.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 fetch has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def fetch
          if @enum
            begin
              ret = @enum.next
            rescue StopIteration
      Severity: Minor
      Found in lib/baza/driver/mysql/unbuffered_result.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 insert_or_handle_duplicate has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def insert_or_handle_duplicate
          @db.insert(@table_name, @updates)
          return @db.last_id if @return_id
        rescue => e
          if (match = e.message.match(/UNIQUE constraint failed: #{Regexp.escape(@table_name)}\.(.+?)(:|\Z|\))/))
      Severity: Minor
      Found in lib/baza/sql_queries/sqlite_upsert_duplicate_key.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 change has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def change(data)
          newdata = data.clone
      
          newdata[:name] = name unless newdata.key?(:name)
          newdata[:type] = type unless newdata.key?(:type)
      Severity: Minor
      Found in lib/baza/driver/sqlite3/column.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 save_model! has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def save_model!(model, args = {})
          raise ActiveRecord::InvalidRecord, model if (!args.key?(:validate) || args[:validate]) && !model.valid?
      
          attributes = {}
          model.changes.each do |column_name, value_array|
      Severity: Minor
      Found in lib/baza/driver/active_record.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 create_sql has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def create_sql(index_data, args)
          sql = ""
          sql << "CREATE" if args[:create] || !args.key?(:create)
      
          if index_data.is_a?(String) || index_data.is_a?(Symbol)
      Severity: Minor
      Found in lib/baza/driver/pg/create_index_sql_creator.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 copy has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def copy(args = {})
          temp_name = "temptable_#{Time.now.to_f.to_s.hash}"
          clone(temp_name)
          cols_cur = columns
          @db.query("DROP TABLE `#{name}`")
      Severity: Minor
      Found in lib/baza/driver/sqlite3/table.rb - About 1 hr to fix

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

          def insert_sql
            sql = "INSERT OR IGNORE INTO #{@db.quote_table(@table_name)} ("
        
            combined_data = @updates.merge(@terms)
        
        
        Severity: Major
        Found in lib/baza/sql_queries/sqlite_upsert_duplicate_key.rb and 1 other location - About 1 hr to fix
        lib/baza/sql_queries/postgres_upsert_duplicate_key.rb on lines 74..96

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

        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 insert_sql
            sql = "INSERT INTO #{@db.quote_table(@table_name)} ("
        
            combined_data = @updates.merge(@terms)
        
        
        Severity: Major
        Found in lib/baza/sql_queries/postgres_upsert_duplicate_key.rb and 1 other location - About 1 hr to fix
        lib/baza/sql_queries/sqlite_upsert_duplicate_key.rb on lines 53..75

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

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

          def change(data)
            if data.key?(:name) && data.fetch(:name).to_s != name
              @db.query("#{alter_table_sql} RENAME #{@db.quote_column(name)} TO #{@db.quote_column(data.fetch(:name))}")
              @name = data.fetch(:name).to_s
            end
        Severity: Minor
        Found in lib/baza/driver/pg/column.rb - About 1 hr to fix

          Method create_indexes has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.create_indexes(index_arr, args = {})
              db = args[:db]
          
              if args[:return_sql]
                sql = ""
          Severity: Minor
          Found in lib/baza/driver/mysql/table.rb - About 1 hr to fix
            Severity
            Category
            Status
            Source
            Language