mongodb/mongo-ruby-driver

View on GitHub
lib/mongo/collection/view/writable.rb

Summary

Maintainability
F
4 days
Test Coverage

File writable.rb has 301 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Mongo
  class Collection
    class View

      # Defines write related behavior for collection view.
Severity: Minor
Found in lib/mongo/collection/view/writable.rb - About 3 hrs to fix

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

            def validate_replacement_documents!(spec)
              if replace = spec.is_a?(Array) ? spec&.first : spec
                if key = replace.keys&.first
                  if key.to_s.start_with?("$")
                    if Mongo.validate_update_replace
    Severity: Minor
    Found in lib/mongo/collection/view/writable.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 find_one_and_update has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

            def find_one_and_update(document, opts = {})
              value = with_session(opts) do |session|
                write_concern = if opts[:write_concern]
                  WriteConcern.get(opts[:write_concern])
                else
    Severity: Minor
    Found in lib/mongo/collection/view/writable.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 find_one_and_update has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def find_one_and_update(document, opts = {})
              value = with_session(opts) do |session|
                write_concern = if opts[:write_concern]
                  WriteConcern.get(opts[:write_concern])
                else
    Severity: Minor
    Found in lib/mongo/collection/view/writable.rb - About 1 hr to fix

      Method update_one has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def update_one(spec, opts = {})
                with_session(opts) do |session|
                  write_concern = if opts[:write_concern]
                    WriteConcern.get(opts[:write_concern])
                  else
      Severity: Minor
      Found in lib/mongo/collection/view/writable.rb - About 1 hr to fix

        Method replace_one has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def replace_one(replacement, opts = {})
                  with_session(opts) do |session|
                    write_concern = if opts[:write_concern]
                      WriteConcern.get(opts[:write_concern])
                    else
        Severity: Minor
        Found in lib/mongo/collection/view/writable.rb - About 1 hr to fix

          Method update_many has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def update_many(spec, opts = {})
                    with_session(opts) do |session|
                      write_concern = if opts[:write_concern]
                        WriteConcern.get(opts[:write_concern])
                      else
          Severity: Minor
          Found in lib/mongo/collection/view/writable.rb - About 1 hr to fix

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

                    def find_one_and_delete(opts = {})
                      with_session(opts) do |session|
                        write_concern = if opts[:write_concern]
                          WriteConcern.get(opts[:write_concern])
                        else
            Severity: Minor
            Found in lib/mongo/collection/view/writable.rb - About 1 hr to fix

              Method delete_one has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      def delete_one(opts = {})
                        with_session(opts) do |session|
                          write_concern = if opts[:write_concern]
                            WriteConcern.get(opts[:write_concern])
                          else
              Severity: Minor
              Found in lib/mongo/collection/view/writable.rb - About 1 hr to fix

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

                        def validate_update_documents!(spec)
                          if update = spec.is_a?(Array) ? spec&.first : spec
                            if key = update.keys&.first
                              unless key.to_s.start_with?("$")
                                if Mongo.validate_update_replace
                Severity: Minor
                Found in lib/mongo/collection/view/writable.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 delete_many has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        def delete_many(opts = {})
                          with_session(opts) do |session|
                            write_concern = if opts[:write_concern]
                              WriteConcern.get(opts[:write_concern])
                            else
                Severity: Minor
                Found in lib/mongo/collection/view/writable.rb - About 1 hr to fix

                  Method update_many has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                          def update_many(spec, opts = {})
                            with_session(opts) do |session|
                              write_concern = if opts[:write_concern]
                                WriteConcern.get(opts[:write_concern])
                              else
                  Severity: Minor
                  Found in lib/mongo/collection/view/writable.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 replace_one has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                          def replace_one(replacement, opts = {})
                            with_session(opts) do |session|
                              write_concern = if opts[:write_concern]
                                WriteConcern.get(opts[:write_concern])
                              else
                  Severity: Minor
                  Found in lib/mongo/collection/view/writable.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 update_one has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                          def update_one(spec, opts = {})
                            with_session(opts) do |session|
                              write_concern = if opts[:write_concern]
                                WriteConcern.get(opts[:write_concern])
                              else
                  Severity: Minor
                  Found in lib/mongo/collection/view/writable.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 delete_one has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                          def delete_one(opts = {})
                            with_session(opts) do |session|
                              write_concern = if opts[:write_concern]
                                WriteConcern.get(opts[:write_concern])
                              else
                  Severity: Minor
                  Found in lib/mongo/collection/view/writable.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 delete_many has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                          def delete_many(opts = {})
                            with_session(opts) do |session|
                              write_concern = if opts[:write_concern]
                                WriteConcern.get(opts[:write_concern])
                              else
                  Severity: Minor
                  Found in lib/mongo/collection/view/writable.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 find_one_and_delete has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                          def find_one_and_delete(opts = {})
                            with_session(opts) do |session|
                              write_concern = if opts[:write_concern]
                                WriteConcern.get(opts[:write_concern])
                              else
                  Severity: Minor
                  Found in lib/mongo/collection/view/writable.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 update_one(spec, opts = {})
                            with_session(opts) do |session|
                              write_concern = if opts[:write_concern]
                                WriteConcern.get(opts[:write_concern])
                              else
                  Severity: Major
                  Found in lib/mongo/collection/view/writable.rb and 1 other location - About 4 hrs to fix
                  lib/mongo/collection/view/writable.rb on lines 355..394

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

                  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 replace_one(replacement, opts = {})
                            with_session(opts) do |session|
                              write_concern = if opts[:write_concern]
                                WriteConcern.get(opts[:write_concern])
                              else
                  Severity: Major
                  Found in lib/mongo/collection/view/writable.rb and 1 other location - About 4 hrs to fix
                  lib/mongo/collection/view/writable.rb on lines 499..538

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

                  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

                              nro_write_with_retry(write_concern, context: context) do |connection, txn_num, context|
                                gte_4_2 = connection.server.description.server_version_gte?('4.2')
                                if !gte_4_2 && opts[:hint] && write_concern && !write_concern.acknowledged?
                                  raise Error::UnsupportedOption.hint_error(unacknowledged_write: true)
                                end
                  Severity: Major
                  Found in lib/mongo/collection/view/writable.rb and 1 other location - About 1 hr to fix
                  lib/mongo/collection/view/writable.rb on lines 249..264

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

                  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

                              nro_write_with_retry(write_concern, context: context) do |connection, txn_num, context|
                                gte_4_4 = connection.server.description.server_version_gte?('4.4')
                                if !gte_4_4 && opts[:hint] && write_concern && !write_concern.acknowledged?
                                  raise Error::UnsupportedOption.hint_error(unacknowledged_write: true)
                                end
                  Severity: Major
                  Found in lib/mongo/collection/view/writable.rb and 1 other location - About 1 hr to fix
                  lib/mongo/collection/view/writable.rb on lines 451..466

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

                  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

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

                              write_with_retry(write_concern, context: context) do |connection, txn_num, context|
                                gte_4_4 = connection.server.description.server_version_gte?('4.4')
                                if !gte_4_4 && opts[:hint] && write_concern && !write_concern.acknowledged?
                                  raise Error::UnsupportedOption.hint_error(unacknowledged_write: true)
                                end
                  Severity: Major
                  Found in lib/mongo/collection/view/writable.rb and 1 other location - About 1 hr to fix
                  lib/mongo/collection/view/writable.rb on lines 84..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 54.

                  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

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

                              write_with_retry(write_concern, context: context) do |connection, txn_num, context|
                                gte_4_4 = connection.server.description.server_version_gte?('4.4')
                                if !gte_4_4 && opts[:hint] && write_concern && !write_concern.acknowledged?
                                  raise Error::UnsupportedOption.hint_error(unacknowledged_write: true)
                                end
                  Severity: Major
                  Found in lib/mongo/collection/view/writable.rb and 1 other location - About 1 hr to fix
                  lib/mongo/collection/view/writable.rb on lines 192..204

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

                  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 validate_update_documents!(spec)
                            if update = spec.is_a?(Array) ? spec&.first : spec
                              if key = update.keys&.first
                                unless key.to_s.start_with?("$")
                                  if Mongo.validate_update_replace
                  Severity: Minor
                  Found in lib/mongo/collection/view/writable.rb and 1 other location - About 40 mins to fix
                  lib/mongo/collection/view/writable.rb on lines 575..582

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

                  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 validate_replacement_documents!(spec)
                            if replace = spec.is_a?(Array) ? spec&.first : spec
                              if key = replace.keys&.first
                                if key.to_s.start_with?("$")
                                  if Mongo.validate_update_replace
                  Severity: Minor
                  Found in lib/mongo/collection/view/writable.rb and 1 other location - About 40 mins to fix
                  lib/mongo/collection/view/writable.rb on lines 553..560

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

                  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