kaspernj/baza_models

View on GitHub

Showing 38 of 38 total issues

Method parse_relation has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def parse_relation
    current_name = []
    relationships = @klass.relationships

    loop do
Severity: Minor
Found in lib/baza_models/ransacker/relationship_scanner.rb - About 1 hr to fix

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

      def bm_paginate_content(collection)
        require "html_gen"
    
        new_params = params.dup.permit!
        current_page = collection.page
    Severity: Minor
    Found in lib/baza_models/helpers/ransacker_helper.rb - About 1 hr to fix

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

        def fire_callbacks(name)
          return if !@@callbacks[name] || !@@callbacks[name][self.class.name]
      
          @@callbacks[name][self.class.name].each do |callback_data|
            if callback_data[:block]
      Severity: Minor
      Found in lib/baza_models/model.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 not has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def not(args)
          args.each do |key, value|
            if value.is_a?(Hash)
              value.each do |hash_key, hash_value|
                if hash_value.is_a?(Array)
      Severity: Minor
      Found in lib/baza_models/query/not.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 destroy_has_many_relations has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def destroy_has_many_relations
          self.class.relationships.each do |relation_name, relation|
            next if relation.fetch(:type) != :has_many || relation[:dependent] != :destroy
      
            __send__(relation_name).each do |model|
      Severity: Minor
      Found in lib/baza_models/model/has_many_relations.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_parts_as_hash has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def join_parts_as_hash
          return @join_parts.first if @join_parts.length == 1
      
          hash = {}
          current_hash = hash
      Severity: Minor
      Found in lib/baza_models/ransacker/relationship_scanner.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 value_with_mode has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def value_with_mode(value)
          if value.is_a?(Array)
            sql = "IN ("
      
            first = true
      Severity: Minor
      Found in lib/baza_models/query.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

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

        def group(name)
          if name.is_a?(Symbol)
            clone(groups: @groups + ["`#{@model.table_name}`.`#{name}`"])
          elsif name.is_a?(String)
            clone(groups: @groups + [name])
      Severity: Minor
      Found in lib/baza_models/query.rb and 1 other location - About 35 mins to fix
      lib/baza_models/query.rb on lines 256..263

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

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

        def create
          unless new_record?
            errors.add(:base, "cannot create unless new record")
            return false
          end
      Severity: Minor
      Found in lib/baza_models/model/manipulation.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 destroy_has_one_relations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def destroy_has_one_relations
          self.class.relationships.each do |relation_name, relation|
            next if relation.fetch(:type) != :has_one || relation[:dependent] != :destroy
      
            model = __send__(relation_name)
      Severity: Minor
      Found in lib/baza_models/model/has_one_relations.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

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

        def order(name)
          if name.is_a?(Symbol)
            clone(orders: @orders + ["`#{@model.table_name}`.`#{name}`"])
          elsif name.is_a?(String)
            clone(orders: @orders + [name])
      Severity: Minor
      Found in lib/baza_models/query.rb and 1 other location - About 35 mins to fix
      lib/baza_models/query.rb on lines 246..253

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

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

        def bm_paginate_content(collection)
          require "html_gen"
      
          new_params = params.dup.permit!
          current_page = collection.page
      Severity: Minor
      Found in lib/baza_models/helpers/ransacker_helper.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 to_enum has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def to_enum
          return autoloaded_cache if should_use_autoload?
      
          array_enum = ArrayEnumerator.new do |yielder|
            @db.query(to_sql).each do |data|
      Severity: Minor
      Found in lib/baza_models/query.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 restrict_has_many_relations has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def restrict_has_many_relations
          self.class.relationships.each do |relation_name, relation|
            next if relation.fetch(:type) != :has_many || relation[:dependent] != :restrict_with_error
      
            if __send__(relation_name).any?
      Severity: Minor
      Found in lib/baza_models/model/has_many_relations.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 << has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def <<(model)
          raise "No previous model set" unless @previous_model
          raise "No relation" unless @relation
      
          if model.persisted?
      Severity: Minor
      Found in lib/baza_models/query.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 inspect has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def inspect
          data_str = ""
          @data.each do |key, value|
            if @changes.key?(key)
              value_to_use = @changes.fetch(key)
      Severity: Minor
      Found in lib/baza_models/model.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 init_model has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.init_model(args = {})
          return if @model_initialized && !args[:force]
      
          @table = db.tables[table_name]
      
      
      Severity: Minor
      Found in lib/baza_models/model.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 restrict_has_one_relations has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def restrict_has_one_relations
          self.class.relationships.each do |relation_name, relation|
            next if relation.fetch(:type) != :has_one || relation[:dependent] != :restrict_with_error
      
            if __send__(relation_name)
      Severity: Minor
      Found in lib/baza_models/model/has_one_relations.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

      Severity
      Category
      Status
      Source
      Language