aergoio/aergo

View on GitHub
consensus/impl/raftv2/waldb.go

Summary

Maintainability
B
4 hrs
Test Coverage
F
0%

Method WalDB.convertFromRaft has 64 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (wal *WalDB) convertFromRaft(entries []raftpb.Entry) ([]*consensus.WalEntry, []*types.Block, []*raftpb.ConfChange) {
    lenEnts := len(entries)
    if lenEnts == 0 {
        return nil, nil, nil
    }
Severity: Minor
Found in consensus/impl/raftv2/waldb.go - About 1 hr to fix

    Method WalDB.convertFromRaft has 10 return statements (exceeds 4 allowed).
    Open

    func (wal *WalDB) convertFromRaft(entries []raftpb.Entry) ([]*consensus.WalEntry, []*types.Block, []*raftpb.ConfChange) {
        lenEnts := len(entries)
        if lenEnts == 0 {
            return nil, nil, nil
        }
    Severity: Major
    Found in consensus/impl/raftv2/waldb.go - About 1 hr to fix

      Method WalDB.convertFromRaft has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
      Open

      func (wal *WalDB) convertFromRaft(entries []raftpb.Entry) ([]*consensus.WalEntry, []*types.Block, []*raftpb.ConfChange) {
          lenEnts := len(entries)
          if lenEnts == 0 {
              return nil, nil, nil
          }
      Severity: Minor
      Found in consensus/impl/raftv2/waldb.go - 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 WalDB.ReadAll has 7 return statements (exceeds 4 allowed).
      Open

      func (wal *WalDB) ReadAll(snapshot *raftpb.Snapshot) (id *consensus.RaftIdentity, state *raftpb.HardState, ents []raftpb.Entry, err error) {
          if id, err = wal.GetIdentity(); err != nil {
              return nil, state, ents, err
          }
      
      
      Severity: Major
      Found in consensus/impl/raftv2/waldb.go - About 45 mins to fix

        Method WalDB.convertWalToRaft has 6 return statements (exceeds 4 allowed).
        Open

        func (wal *WalDB) convertWalToRaft(walEntry *consensus.WalEntry) (*raftpb.Entry, error) {
            var raftEntry = &raftpb.Entry{Term: walEntry.Term, Index: walEntry.Index}
        
            getDataFromWalEntry := func(walEntry *consensus.WalEntry) ([]byte, error) {
                if walEntry.Type != consensus.EntryBlock {
        Severity: Major
        Found in consensus/impl/raftv2/waldb.go - About 40 mins to fix

          There are no issues that match your filters.

          Category
          Status