3scale/porta

View on GitHub
app/lib/event_store/repository.rb

Summary

Maintainability
A
1 hr
Test Coverage

Method initialize has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def initialize(repository = self.class.repository, event_broker = EventBroker.new)
      @client = ::RailsEventStore::Client.new(repository: repository, event_broker: event_broker)
      @facade = Facade.new(repository, event_broker)

      @client.subscribe_to_all_events(AfterCommitSubscriber.new)
Severity: Minor
Found in app/lib/event_store/repository.rb - About 1 hr to fix

    EventStore::Repository::Facade#publish_event has approx 10 statements
    Open

          def publish_event(event, stream_name = RubyEventStore::GLOBAL_STREAM, expected_version = :any)
    Severity: Minor
    Found in app/lib/event_store/repository.rb by reek

    A method with Too Many Statements is any method that has a large number of lines.

    Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

    So the following method would score +6 in Reek's statement-counting algorithm:

    def parse(arg, argv, &error)
      if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
        return nil, block, nil                                         # +1
      end
      opt = (val = parse_arg(val, &error))[1]                          # +2
      val = conv_arg(*val)                                             # +3
      if opt and !arg
        argv.shift                                                     # +4
      else
        val[0] = nil                                                   # +5
      end
      val                                                              # +6
    end

    (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

    EventStore::Repository::Facade takes parameters ['event', 'stream_name'] to 3 methods
    Open

          def publish_event(event, stream_name = RubyEventStore::GLOBAL_STREAM, expected_version = :any)
            logger.debug { "[EventStore] publishing #{event.class} #{event.event_id}" } if event
    
            append_to_stream(stream_name, event, expected_version)
            event_broker.notify_subscribers(event)
    Severity: Minor
    Found in app/lib/event_store/repository.rb by reek

    In general, a Data Clump occurs when the same two or three items frequently appear together in classes and parameter lists, or when a group of instance variable names start or end with similar substrings.

    The recurrence of the items often means there is duplicate code spread around to handle them. There may be an abstraction missing from the code, making the system harder to understand.

    Example

    Given

    class Dummy
      def x(y1,y2); end
      def y(y1,y2); end
      def z(y1,y2); end
    end

    Reek would emit the following warning:

    test.rb -- 1 warning:
      [2, 3, 4]:Dummy takes parameters [y1, y2] to 3 methods (DataClump)

    A possible way to fix this problem (quoting from Martin Fowler):

    The first step is to replace data clumps with objects and use the objects whenever you see them. An immediate benefit is that you'll shrink some parameter lists. The interesting stuff happens as you begin to look for behavior to move into the new objects.

    EventStore::Repository::Facade::InvalidEventError#record is a writable attribute
    Open

            attr_accessor :record
    Severity: Minor
    Found in app/lib/event_store/repository.rb by reek

    A class that publishes a setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.

    The same holds to a lesser extent for getters, but Reek doesn't flag those.

    Example

    Given:

    class Klass
      attr_accessor :dummy
    end

    Reek would emit the following warning:

    reek test.rb
    
    test.rb -- 1 warning:
      [2]:Klass declares the writable attribute dummy (Attribute)

    EventStore::Repository::Facade has missing safe method 'create_event!'
    Open

          def create_event!(event, stream_name)
    Severity: Minor
    Found in app/lib/event_store/repository.rb by reek

    A candidate method for the Missing Safe Method smell are methods whose names end with an exclamation mark.

    An exclamation mark in method names means (the explanation below is taken from here ):

    The ! in method names that end with ! means, “This method is dangerous”—or, more precisely, this method is the “dangerous” version of an otherwise equivalent method, with the same name minus the !. “Danger” is relative; the ! doesn’t mean anything at all unless the method name it’s in corresponds to a similar but bang-less method name. So, for example, gsub! is the dangerous version of gsub. exit! is the dangerous version of exit. flatten! is the dangerous version of flatten. And so forth.

    Such a method is called Missing Safe Method if and only if her non-bang version does not exist and this method is reported as a smell.

    Example

    Given

    class C
      def foo; end
      def foo!; end
      def bar!; end
    end

    Reek would report bar! as Missing Safe Method smell but not foo!.

    Reek reports this smell only in a class context, not in a module context in order to allow perfectly legit code like this:

    class Parent
      def foo; end
    end
    
    module Dangerous
      def foo!; end
    end
    
    class Son < Parent
      include Dangerous
    end
    
    class Daughter < Parent
    end

    In this example, Reek would not report the Missing Safe Method smell for the method foo of the Dangerous module.

    There are no issues that match your filters.

    Category
    Status