arkency/rails_event_store

View on GitHub

Showing 76 of 76 total issues

Method read_scope has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

      def read_scope(spec)
        if spec.stream.global?
          stream = @event_klass
          stream = stream.where(event_id: spec.with_ids) if spec.with_ids?
          stream = stream.where(event_type: spec.with_types) if spec.with_types?

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 event_repository.rb has 340 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module RubyEventStore
  module Sequel
    class EventRepository
      UPSERT_COLUMNS = %i[event_type data metadata valid_at].freeze

    Class Specification has 30 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Specification
        DEFAULT_BATCH_SIZE = 100
    
        # @api private
        # @private
    Severity: Minor
    Found in ruby_event_store/lib/ruby_event_store/specification.rb - About 3 hrs to fix

      Class EventRepositoryReader has 29 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class EventRepositoryReader
            def initialize(event_klass, stream_klass, serializer)
              @event_klass = event_klass
              @stream_klass = stream_klass
              @serializer = serializer

        Class EventRepository has 29 methods (exceeds 20 allowed). Consider refactoring.
        Open

            class EventRepository
              UPSERT_COLUMNS = %i[event_type data metadata valid_at].freeze
        
              def initialize(sequel:, serializer:)
                @serializer = serializer

          Class SpecificationResult has 28 methods (exceeds 20 allowed). Consider refactoring.
          Open

            class SpecificationResult
              def initialize(
                direction: :forward,
                start: nil,
                stop: nil,
          Severity: Minor
          Found in ruby_event_store/lib/ruby_event_store/specification_result.rb - About 3 hrs to fix

            Class Client has 28 methods (exceeds 20 allowed). Consider refactoring.
            Open

              class Client
                def initialize(
                  repository: InMemoryRepository.new,
                  mapper: Mappers::Default.new,
                  subscriptions: Subscriptions.new,
            Severity: Minor
            Found in ruby_event_store/lib/ruby_event_store/client.rb - About 3 hrs to fix

              Method read_scope has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
              Open

                      def read_scope(specification)
                        direction = specification.forward? ? :forward : :backward
              
                        if specification.last? && !specification.start && !specification.stop
                          direction = specification.forward? ? :backward : :forward

              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

              Class InMemoryRepository has 27 methods (exceeds 20 allowed). Consider refactoring.
              Open

                class InMemoryRepository
                  class UnsupportedVersionAnyUsage < StandardError
                    def initialize
                      super <<~EOS
                      Mixing expected version :any and specific position (or :auto) is unsupported.
              Severity: Minor
              Found in ruby_event_store/lib/ruby_event_store/in_memory_repository.rb - About 3 hrs to fix

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

                  module Sequel
                    class IndexViolationDetector
                      def initialize(event_store_events, event_store_events_in_streams)
                        @postgres_pkey_error = "Key (event_id)".freeze
                        @postgres_index_error = "Key (stream, event_id)".freeze
                ruby_event_store-active_record/lib/ruby_event_store/active_record/index_violation_detector.rb on lines 4..40

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

                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

                  module ActiveRecord
                    class IndexViolationDetector
                      def initialize(event_store_events, event_store_events_in_streams)
                        @postgres_pkey_error = "Key (event_id)".freeze
                        @postgres_index_error = "Key (stream, event_id)".freeze
                contrib/ruby_event_store-sequel/lib/ruby_event_store/sequel/index_violation_detector.rb on lines 4..40

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

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

                      def read_from_global_stream(specification)
                        dataset =
                          @db[:event_store_events]
                            .select(
                              ::Sequel[:event_store_events][:event_id],

                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

                Class EventRepository has 23 methods (exceeds 20 allowed). Consider refactoring.
                Open

                    class EventRepository
                      POSITION_SHIFT = 1
                
                      def initialize(model_factory: WithDefaultModels.new, serializer:)
                        @serializer = serializer

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

                        def read_from_specific_stream(specification)
                          dataset =
                            @db[:event_store_events]
                              .join(:event_store_events_in_streams, event_id: :event_id)
                              .select(

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

                          def failure_message(expected, events, stream_name = nil)
                            return failure_message_strict(expected, events) if expected.strict?
                            return failure_message_no_events if expected.empty?
                            expected.events.each do |expected_event|
                              correct_event_count = 0

                  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 parse has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          def self.parse(argv)
                            options = Options.new(*DEFAULTS.values)
                            OptionParser
                              .new do |option_parser|
                                option_parser.banner = "Usage: res_outbox [options]"
                  Severity: Major
                  Found in contrib/ruby_event_store-outbox/lib/ruby_event_store/outbox/cli.rb - About 2 hrs to fix

                    Method read_from_specific_stream has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                          def read_from_specific_stream(specification)
                            dataset =
                              @db[:event_store_events]
                                .join(:event_store_events_in_streams, event_id: :event_id)
                                .select(

                      Method read has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                      Open

                              def read(specification, serializer)
                                query = read_scope(specification)
                      
                                if specification.batched?
                                  BatchEnumerator.new(

                      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 call has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                            def call(env)
                              router = Router.new(routing)
                              router.add_route("GET", "/api/events/:event_id") do |params|
                                json GetEvent.new(event_store: event_store, event_id: params.fetch("event_id"))
                              end
                      Severity: Minor
                      Found in ruby_event_store-browser/lib/ruby_event_store/browser/app.rb - About 1 hr to fix

                        Method read_from_global_stream has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                              def read_from_global_stream(specification)
                                dataset =
                                  @db[:event_store_events]
                                    .select(
                                      ::Sequel[:event_store_events][:event_id],
                          Severity
                          Category
                          Status
                          Source
                          Language