mongoid/mongoid-history

View on GitHub

Showing 20 of 20 total issues

File trackable.rb has 386 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Mongoid
  module History
    module Trackable
      extend ActiveSupport::Concern

Severity: Minor
Found in lib/mongoid/history/trackable.rb - About 5 hrs to fix

    Method related_scope has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

            def related_scope
              scope = history_trackable_options[:scope]
    
              # Use top level document if its name is specified in the scope
              root_document_name = traverse_association_chain.first['name'].singularize.underscore.tr('/', '_').to_sym
    Severity: Minor
    Found in lib/mongoid/history/trackable.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

    Method get_versions_criteria has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

            def get_versions_criteria(options_or_version)
              if options_or_version.is_a? Hash
                options = options_or_version
                if options[:from] && options[:to]
                  lower = options[:from] >= options[:to] ? options[:to] : options[:from]
    Severity: Minor
    Found in lib/mongoid/history/trackable.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

    Method tracked_edits has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

          def tracked_edits
            return @tracked_edits if @tracked_edits
            @tracked_edits = HashWithIndifferentAccess.new
    
            tracked_changes.each do |k, v|
    Severity: Minor
    Found in lib/mongoid/history/tracker.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

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

            def track_history(options = {})
              extend RelationMethods
    
              history_options = Mongoid::History::Options.new(self, options)
    
    
    Severity: Minor
    Found in lib/mongoid/history/trackable.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 prepare_formatted_fields has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

          def prepare_formatted_fields
            formats = {}
    
            if @prepared[:format].class == Hash
              @prepared[:format].each do |field, format|
    Severity: Minor
    Found in lib/mongoid/history/options.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 traverse_association_chain has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

          def traverse_association_chain
            chain = association_chain.dup
            doc = nil
            documents = []
            loop do
    Severity: Minor
    Found in lib/mongoid/history/tracker.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 attributes has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def attributes
          @attributes = {}
          trackable.attributes.each do |k, v|
            next unless trackable_class.tracked_field?(k, :create)
            modified = if changes[k]
    Severity: Minor
    Found in perf/benchmark_modified_attributes_for_create.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 changes_from_parent has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

            def changes_from_parent
              parent_changes = {}
              changes.each do |k, v|
                change_value = begin
                  if trackable_class.tracked_embeds_one?(k)
    Severity: Minor
    Found in lib/mongoid/history/attributes/update.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 association_hash has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

            def association_hash(node = self)
              # We prefer to look up associations through the parent record because
              # we're assured, through the object creation, it'll exist. Whereas we're not guaranteed
              # the child to parent (embedded_in, belongs_to) relation will be defined
              if node._parent
    Severity: Minor
    Found in lib/mongoid/history/trackable.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

    Avoid deeply nested control flow statements.
    Open

                  scope = _association.inverse_class_name.tableize.singularize.to_sym if _association.present? && scope == _association.as
    Severity: Major
    Found in lib/mongoid/history/trackable.rb - About 45 mins to fix

      Method parse_tracked_fields_and_relations has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def parse_tracked_fields_and_relations
              # case `options[:on]`
              # when `posts: [:id, :title]`, then it will convert it to `[[:posts, [:id, :title]]]`
              # when `:foo`, then `[:foo]`
              # when `[:foo, { posts: [:id, :title] }]`, then return as is
      Severity: Minor
      Found in lib/mongoid/history/options.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 track_history_for_action has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

              def track_history_for_action(action)
                if track_history_for_action?(action)
                  current_version = increment_current_version?(action) ? increment_current_version : next_version
                  last_track = self.class.tracker_class.create!(
                    history_tracker_attributes(action.to_sym)
      Severity: Minor
      Found in lib/mongoid/history/trackable.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 undo!(modifier = nil)
              if action.to_sym == :destroy
                re_create
              elsif action.to_sym == :create
                re_destroy
      Severity: Minor
      Found in lib/mongoid/history/tracker.rb and 1 other location - About 30 mins to fix
      lib/mongoid/history/tracker.rb on lines 41..50

      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 redo!(modifier = nil)
              if action.to_sym == :destroy
                re_destroy
              elsif action.to_sym == :create
                re_create
      Severity: Minor
      Found in lib/mongoid/history/tracker.rb and 1 other location - About 30 mins to fix
      lib/mongoid/history/tracker.rb on lines 29..38

      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

      Method categorize_tracked_option has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def categorize_tracked_option(field, field_options = nil)
              return if @prepared[:except].include?(field)
              return if reserved_fields.include?(field)
      
              field_options = Array(field_options)
      Severity: Minor
      Found in lib/mongoid/history/options.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 transform_changes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def transform_changes(changes)
                original = {}
                modified = {}
                changes.each_pair do |k, modification_pair|
                  o, m = modification_pair
      Severity: Minor
      Found in lib/mongoid/history/trackable.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 embeds_one_changes_from_embedded_documents has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def embeds_one_changes_from_embedded_documents
                embedded_doc_changes = {}
                trackable_class.tracked_embeds_one.each do |rel|
                  rel_class = trackable_class.relation_class_of(rel)
                  paranoia_field = Mongoid::History.trackable_class_settings(rel_class)[:paranoia_field]
      Severity: Minor
      Found in lib/mongoid/history/attributes/update.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 insert_embeds_one_changes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def insert_embeds_one_changes
                trackable_class.tracked_embeds_one.each do |rel|
                  rel_class = trackable_class.relation_class_of(rel)
                  paranoia_field = Mongoid::History.trackable_class_settings(rel_class)[:paranoia_field]
                  paranoia_field = rel_class.aliased_fields.key(paranoia_field) || paranoia_field
      Severity: Minor
      Found in lib/mongoid/history/attributes/create.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 format_relation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def format_relation(relation_class, obj, permitted_attrs, formats)
                obj.inject({}) do |m, field_value|
                  field = relation_class.database_field_name(field_value.first)
                  next m unless permitted_attrs.include?(field)
      
      
      Severity: Minor
      Found in lib/mongoid/history/attributes/base.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