synapsecns/sanguine

View on GitHub
services/explorer/consumer/parser/swapparser.go

Summary

Maintainability
F
4 days
Test Coverage

Method SwapParser.Parse has a Cognitive Complexity of 132 (exceeds 20 allowed). Consider refactoring.
Open

func (p *SwapParser) Parse(ctx context.Context, log ethTypes.Log, chainID uint32) (interface{}, error) {
    logTopic := log.Topics[0]

    iFace, err := func(log ethTypes.Log) (swapTypes.EventLog, error) {
        // nolint:nestif
Severity: Minor
Found in services/explorer/consumer/parser/swapparser.go - About 2 days 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 SwapParser.Parse has 238 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (p *SwapParser) Parse(ctx context.Context, log ethTypes.Log, chainID uint32) (interface{}, error) {
    logTopic := log.Topics[0]

    iFace, err := func(log ethTypes.Log) (swapTypes.EventLog, error) {
        // nolint:nestif
Severity: Major
Found in services/explorer/consumer/parser/swapparser.go - About 1 day to fix

    Method SwapParser.Parse has 41 return statements (exceeds 4 allowed).
    Open

    func (p *SwapParser) Parse(ctx context.Context, log ethTypes.Log, chainID uint32) (interface{}, error) {
        logTopic := log.Topics[0]
    
        iFace, err := func(log ethTypes.Log) (swapTypes.EventLog, error) {
            // nolint:nestif
    Severity: Major
    Found in services/explorer/consumer/parser/swapparser.go - About 3 hrs to fix

      Function eventToSwapEvent has 60 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func eventToSwapEvent(event swapTypes.EventLog, chainID uint32) model.SwapEvent {
          var buyer sql.NullString
      
          if event.GetBuyer() != nil {
              buyer.Valid = true
      Severity: Minor
      Found in services/explorer/consumer/parser/swapparser.go - About 1 hr to fix

        Function NewSwapParser has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        func NewSwapParser(consumerDB db.ConsumerDB, swapAddress common.Address, metaSwap bool, consumerFetcher fetcher.ScribeFetcher, swapService fetcher.SwapService, tokenDataService tokendata.Service, tokenPriceService tokenprice.Service) (*SwapParser, error) {
        Severity: Major
        Found in services/explorer/consumer/parser/swapparser.go - About 50 mins to fix

          Method SwapParser.GetCorrectSwapFee has 6 return statements (exceeds 4 allowed).
          Open

          func (p *SwapParser) GetCorrectSwapFee(ctx context.Context, swapEvent model.SwapEvent) (uint64, uint64, error) {
              var dbAdminFee uint64
              var dbSwapFee uint64
              var err error
              g, groupCtx := errgroup.WithContext(ctx)
          Severity: Major
          Found in services/explorer/consumer/parser/swapparser.go - About 40 mins to fix

            Function NewSwapParser has 5 return statements (exceeds 4 allowed).
            Open

            func NewSwapParser(consumerDB db.ConsumerDB, swapAddress common.Address, metaSwap bool, consumerFetcher fetcher.ScribeFetcher, swapService fetcher.SwapService, tokenDataService tokendata.Service, tokenPriceService tokenprice.Service) (*SwapParser, error) {
                var filterer *swap.SwapFlashLoanFilterer
                var filtererMetaSwap *metaswap.MetaSwapFilterer
                var err error
                if metaSwap {
            Severity: Major
            Found in services/explorer/consumer/parser/swapparser.go - About 35 mins to fix

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

                          case swap.Topic(swapTypes.NewAdminFeeEvent):
                              iFace, err := p.Filterer.ParseNewAdminFee(log)
                              if err != nil {
                                  return nil, fmt.Errorf("could not parse new admin fee: %w", err)
                              }
              Severity: Major
              Found in services/explorer/consumer/parser/swapparser.go and 1 other location - About 1 hr to fix
              services/explorer/consumer/parser/swapparser.go on lines 258..267

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

              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

                          case swap.Topic(swapTypes.NewSwapFeeEvent):
                              iFace, err := p.Filterer.ParseNewSwapFee(log)
                              if err != nil {
                                  return nil, fmt.Errorf("could not parse new swap fee: %w", err)
                              }
              Severity: Major
              Found in services/explorer/consumer/parser/swapparser.go and 1 other location - About 1 hr to fix
              services/explorer/consumer/parser/swapparser.go on lines 248..257

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

              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 3 locations. Consider refactoring.
              Open

              func (p *SwapParser) EventType(log ethTypes.Log) (_ swapTypes.EventType, ok bool) {
                  for _, logTopic := range log.Topics {
                      eventType := swap.EventTypeFromTopic(logTopic)
                      if eventType == nil {
                          continue
              Severity: Major
              Found in services/explorer/consumer/parser/swapparser.go and 2 other locations - About 50 mins to fix
              services/explorer/consumer/parser/bridgeparser.go on lines 86..98
              services/explorer/consumer/parser/messagebusparser.go on lines 43..53

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

              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

              There are no issues that match your filters.

              Category
              Status