mongodb/mongo-ruby-driver

View on GitHub
lib/mongo/bulk_write.rb

Summary

Maintainability
D
2 days
Test Coverage

Method validate_requests! has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
Open

    def validate_requests!
      requests_empty = true
      @requests.each do |req|
        requests_empty = false
        if op = req.keys.first
Severity: Minor
Found in lib/mongo/bulk_write.rb - About 7 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 execute has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def execute
      operation_id = Monitoring.next_operation_id
      result_combiner = ResultCombiner.new
      operations = op_combiner.combine
      validate_requests!
Severity: Minor
Found in lib/mongo/bulk_write.rb - About 1 hr to fix

    Method validate_requests! has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def validate_requests!
          requests_empty = true
          @requests.each do |req|
            requests_empty = false
            if op = req.keys.first
    Severity: Minor
    Found in lib/mongo/bulk_write.rb - About 1 hr to fix

      Method split_execute has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def split_execute(name, values, connection, context, operation_id, result_combiner, session, txn_num)
      Severity: Major
      Found in lib/mongo/bulk_write.rb - About 1 hr to fix

        Method execute_operation has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def execute_operation(name, values, connection, context, operation_id, result_combiner, session, txn_num = nil)
        Severity: Major
        Found in lib/mongo/bulk_write.rb - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                          unless key.to_s.start_with?("$")
                            if Mongo.validate_update_replace
                              raise Error::InvalidUpdateDocument.new(key: key)
                            else
                              Error::InvalidUpdateDocument.warn(Logger.logger, key)
          Severity: Major
          Found in lib/mongo/bulk_write.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                          if key.to_s.start_with?("$")
                            if Mongo.validate_update_replace
                              raise Error::InvalidReplacementDocument.new(key: key)
                            else
                              Error::InvalidReplacementDocument.warn(Logger.logger, key)
            Severity: Major
            Found in lib/mongo/bulk_write.rb - About 45 mins to fix

              Method update_one has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def update_one(documents, connection, context, operation_id, session, txn_num)
              Severity: Minor
              Found in lib/mongo/bulk_write.rb - About 45 mins to fix

                Method delete_one has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def delete_one(documents, connection, context, operation_id, session, txn_num)
                Severity: Minor
                Found in lib/mongo/bulk_write.rb - About 45 mins to fix

                  Method delete_many has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def delete_many(documents, connection, context, operation_id, session, txn_num)
                  Severity: Minor
                  Found in lib/mongo/bulk_write.rb - About 45 mins to fix

                    Method update_many has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def update_many(documents, connection, context, operation_id, session, txn_num)
                    Severity: Minor
                    Found in lib/mongo/bulk_write.rb - About 45 mins to fix

                      Method insert_one has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def insert_one(documents, connection, context, operation_id, session, txn_num)
                      Severity: Minor
                      Found in lib/mongo/bulk_write.rb - About 45 mins to fix

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

                            def can_hint?(connection)
                              gte_4_2 = connection.server.description.server_version_gte?('4.2')
                              gte_4_4 = connection.server.description.server_version_gte?('4.4')
                              op_combiner.requests.all? do |req|
                                op = req.keys.first
                        Severity: Minor
                        Found in lib/mongo/bulk_write.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 execute_operation has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def execute_operation(name, values, connection, context, operation_id, result_combiner, session, txn_num = nil)
                              validate_collation!(connection)
                              validate_array_filters!(connection)
                              validate_hint!(connection)
                        
                        
                        Severity: Minor
                        Found in lib/mongo/bulk_write.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 3 locations. Consider refactoring.
                        Open

                            def delete_one(documents, connection, context, operation_id, session, txn_num)
                              QueryCache.clear_namespace(collection.namespace)
                        
                              spec = base_spec(operation_id, session).merge(:deletes => documents, :txn_num => txn_num)
                              Operation::Delete.new(spec).bulk_execute(connection, context: context)
                        Severity: Minor
                        Found in lib/mongo/bulk_write.rb and 2 other locations - About 15 mins to fix
                        lib/mongo/bulk_write.rb on lines 243..247
                        lib/mongo/bulk_write.rb on lines 250..254

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

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

                            def update_one(documents, connection, context, operation_id, session, txn_num)
                              QueryCache.clear_namespace(collection.namespace)
                        
                              spec = base_spec(operation_id, session).merge(:updates => documents, :txn_num => txn_num)
                              Operation::Update.new(spec).bulk_execute(connection, context: context)
                        Severity: Minor
                        Found in lib/mongo/bulk_write.rb and 2 other locations - About 15 mins to fix
                        lib/mongo/bulk_write.rb on lines 229..233
                        lib/mongo/bulk_write.rb on lines 243..247

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

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

                            def insert_one(documents, connection, context, operation_id, session, txn_num)
                              QueryCache.clear_namespace(collection.namespace)
                        
                              spec = base_spec(operation_id, session).merge(:documents => documents, :txn_num => txn_num)
                              Operation::Insert.new(spec).bulk_execute(connection, context: context)
                        Severity: Minor
                        Found in lib/mongo/bulk_write.rb and 2 other locations - About 15 mins to fix
                        lib/mongo/bulk_write.rb on lines 229..233
                        lib/mongo/bulk_write.rb on lines 250..254

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

                        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