mongodb/mongo-ruby-driver

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

Summary

Maintainability
D
2 days
Test Coverage

Class View has 34 methods (exceeds 20 allowed). Consider refactoring.
Open

    class View

      # Defines read related behavior for collection view.
      #
      # @since 2.0.0
Severity: Minor
Found in lib/mongo/collection/view/readable.rb - About 4 hrs to fix

    Method estimated_document_count has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

            def estimated_document_count(opts = {})
              unless view.filter.empty?
                raise ArgumentError, "Cannot call estimated_document_count when querying with a filter"
              end
    
    
    Severity: Minor
    Found in lib/mongo/collection/view/readable.rb - About 3 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

    File readable.rb has 270 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Mongo
      class Collection
        class View
    
          # Defines read related behavior for collection view.
    Severity: Minor
    Found in lib/mongo/collection/view/readable.rb - About 2 hrs to fix

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

              def estimated_document_count(opts = {})
                unless view.filter.empty?
                  raise ArgumentError, "Cannot call estimated_document_count when querying with a filter"
                end
      
      
      Severity: Minor
      Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

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

                def parallel_scan(cursor_count, options = {})
                  if options[:session]
                    # The session would be overwritten by the one in +options+ later.
                    session = client.send(:get_session, @options)
                  else
        Severity: Minor
        Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

          Method distinct has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def distinct(field_name, opts = {})
                    if field_name.nil?
                      raise ArgumentError, 'Field name for distinct operation must be not nil'
                    end
                    opts = @options.merge(opts) unless Mongo.broken_view_options
          Severity: Minor
          Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

            Method count has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def count(opts = {})
                      opts = @options.merge(opts) unless Mongo.broken_view_options
                      cmd = { :count => collection.name, :query => filter }
                      cmd[:skip] = opts[:skip] if opts[:skip]
                      cmd[:hint] = opts[:hint] if opts[:hint]
            Severity: Minor
            Found in lib/mongo/collection/view/readable.rb - About 1 hr to fix

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

                      def count(opts = {})
                        opts = @options.merge(opts) unless Mongo.broken_view_options
                        cmd = { :count => collection.name, :query => filter }
                        cmd[:skip] = opts[:skip] if opts[:skip]
                        cmd[:hint] = opts[:hint] if opts[:hint]
              Severity: Minor
              Found in lib/mongo/collection/view/readable.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 count_documents has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                      def count_documents(opts = {})
                        opts = @options.merge(opts) unless Mongo.broken_view_options
                        pipeline = [:'$match' => filter]
                        pipeline << { :'$skip' => opts[:skip] } if opts[:skip]
                        pipeline << { :'$limit' => opts[:limit] } if opts[:limit]
              Severity: Minor
              Found in lib/mongo/collection/view/readable.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 distinct has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                      def distinct(field_name, opts = {})
                        if field_name.nil?
                          raise ArgumentError, 'Field name for distinct operation must be not nil'
                        end
                        opts = @options.merge(opts) unless Mongo.broken_view_options
              Severity: Minor
              Found in lib/mongo/collection/view/readable.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

              There are no issues that match your filters.

              Category
              Status