tulir/gomuks

View on GitHub
matrix/history.go

Summary

Maintainability
C
1 day
Test Coverage

Method HistoryManager.store has a Cognitive Complexity of 43 (exceeds 20 allowed). Consider refactoring.
Open

func (hm *HistoryManager) store(room *rooms.Room, events []*event.Event, append bool) (newEvents []*muksevt.Event, newPtrStart uint64, err error) {
    hm.Lock()
    defer hm.Unlock()
    newEvents = make([]*muksevt.Event, len(events))
    err = hm.db.Update(func(tx *bolt.Tx) error {
Severity: Minor
Found in matrix/history.go - About 4 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 HistoryManager.store has 62 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (hm *HistoryManager) store(room *rooms.Room, events []*event.Event, append bool) (newEvents []*muksevt.Event, newPtrStart uint64, err error) {
    hm.Lock()
    defer hm.Unlock()
    newEvents = make([]*muksevt.Event, len(events))
    err = hm.db.Update(func(tx *bolt.Tx) error {
Severity: Minor
Found in matrix/history.go - About 1 hr to fix

    Method HistoryManager.store has 10 return statements (exceeds 4 allowed).
    Open

    func (hm *HistoryManager) store(room *rooms.Room, events []*event.Event, append bool) (newEvents []*muksevt.Event, newPtrStart uint64, err error) {
        hm.Lock()
        defer hm.Unlock()
        newEvents = make([]*muksevt.Event, len(events))
        err = hm.db.Update(func(tx *bolt.Tx) error {
    Severity: Major
    Found in matrix/history.go - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

              } else if err := stream.Put(index, eventData); err != nil {
                  return err
              }
      Severity: Major
      Found in matrix/history.go - About 45 mins to fix

        Function NewHistoryManager has 7 return statements (exceeds 4 allowed).
        Open

        func NewHistoryManager(dbPath string) (*HistoryManager, error) {
            hm := &HistoryManager{
                historyEndPtr: make(map[*rooms.Room]uint64),
            }
            db, err := bolt.Open(dbPath, 0600, &bolt.Options{
        Severity: Major
        Found in matrix/history.go - About 45 mins to fix

          Method HistoryManager.Load has 5 return statements (exceeds 4 allowed).
          Open

          func (hm *HistoryManager) Load(room *rooms.Room, num int, ptrStart uint64) (events []*muksevt.Event, newPtrStart uint64, err error) {
              hm.Lock()
              defer hm.Unlock()
              err = hm.db.View(func(tx *bolt.Tx) error {
                  stream := tx.Bucket(bucketRoomStreams).Bucket([]byte(room.ID))
          Severity: Major
          Found in matrix/history.go - About 35 mins to fix

            error var RoomNotFoundError should have name of the form ErrFoo
            Open

                RoomNotFoundError  = errors.New("room not found")
            Severity: Minor
            Found in matrix/history.go by golint

            error var EventNotFoundError should have name of the form ErrFoo
            Open

                EventNotFoundError = errors.New("event not found")
            Severity: Minor
            Found in matrix/history.go by golint

            There are no issues that match your filters.

            Category
            Status