synapsecns/sanguine

View on GitHub
services/rfq/relayer/inventory/manager.go

Summary

Maintainability
F
3 days
Test Coverage

Method inventoryManagerImpl.ApproveAllTokens has a Cognitive Complexity of 64 (exceeds 20 allowed). Consider refactoring.
Open

func (i *inventoryManagerImpl) ApproveAllTokens(ctx context.Context) (err error) {
    ctx, span := i.handler.Tracer().Start(ctx, "approveAllTokens")
    defer func() {
        metrics.EndSpanWithErr(span, err)
    }()
Severity: Minor
Found in services/rfq/relayer/inventory/manager.go - About 7 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

File manager.go has 567 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package inventory

import (
    "context"
    "errors"
Severity: Minor
Found in services/rfq/relayer/inventory/manager.go - About 3 hrs to fix

    Method inventoryManagerImpl.Start has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring.
    Open

    func (i *inventoryManagerImpl) Start(ctx context.Context) error {
        g, ctx := errgroup.WithContext(ctx)
        for _, rebalanceManager := range i.rebalanceManagers {
            rebalanceManager := rebalanceManager
            g.Go(func() error {
    Severity: Minor
    Found in services/rfq/relayer/inventory/manager.go - About 2 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 inventoryManagerImpl.ApproveAllTokens has 78 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (i *inventoryManagerImpl) ApproveAllTokens(ctx context.Context) (err error) {
        ctx, span := i.handler.Tracer().Start(ctx, "approveAllTokens")
        defer func() {
            metrics.EndSpanWithErr(span, err)
        }()
    Severity: Major
    Found in services/rfq/relayer/inventory/manager.go - About 2 hrs to fix

      Method inventoryManagerImpl.initializeTokens has 73 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (i *inventoryManagerImpl) initializeTokens(parentCtx context.Context, cfg relconfig.Config) (err error) {
          i.mux.Lock()
          defer i.mux.Unlock()
      
          ctx, span := i.handler.Tracer().Start(parentCtx, "initializeTokens", trace.WithAttributes(
      Severity: Minor
      Found in services/rfq/relayer/inventory/manager.go - About 1 hr to fix

        Method inventoryManagerImpl.ApproveAllTokens has 13 return statements (exceeds 4 allowed).
        Open

        func (i *inventoryManagerImpl) ApproveAllTokens(ctx context.Context) (err error) {
            ctx, span := i.handler.Tracer().Start(ctx, "approveAllTokens")
            defer func() {
                metrics.EndSpanWithErr(span, err)
            }()
        Severity: Major
        Found in services/rfq/relayer/inventory/manager.go - About 1 hr to fix

          Method inventoryManagerImpl.Start has 53 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (i *inventoryManagerImpl) Start(ctx context.Context) error {
              g, ctx := errgroup.WithContext(ctx)
              for _, rebalanceManager := range i.rebalanceManagers {
                  rebalanceManager := rebalanceManager
                  g.Go(func() error {
          Severity: Minor
          Found in services/rfq/relayer/inventory/manager.go - About 1 hr to fix

            Method inventoryManagerImpl.initializeTokens has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
            Open

            func (i *inventoryManagerImpl) initializeTokens(parentCtx context.Context, cfg relconfig.Config) (err error) {
                i.mux.Lock()
                defer i.mux.Unlock()
            
                ctx, span := i.handler.Tracer().Start(parentCtx, "initializeTokens", trace.WithAttributes(
            Severity: Minor
            Found in services/rfq/relayer/inventory/manager.go - About 1 hr 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 inventoryManagerImpl.approve has 10 return statements (exceeds 4 allowed).
            Open

            func (i *inventoryManagerImpl) approve(parentCtx context.Context, tokenAddr, contractAddr common.Address, backendClient client.EVM) (err error) {
                ctx, span := i.handler.Tracer().Start(parentCtx, "approve", trace.WithAttributes(
                    attribute.String("token_address", tokenAddr.Hex()),
                    attribute.String("contract_address", contractAddr.Hex()),
                ))
            Severity: Major
            Found in services/rfq/relayer/inventory/manager.go - About 1 hr to fix

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

              func NewInventoryManager(ctx context.Context, clientFetcher submitter.ClientFetcher, handler metrics.Handler, cfg relconfig.Config, relayer common.Address, txSubmitter submitter.TransactionSubmitter, db reldb.Service) (Manager, error) {
              Severity: Major
              Found in services/rfq/relayer/inventory/manager.go - About 50 mins to fix

                Method inventoryManagerImpl.Start has 8 return statements (exceeds 4 allowed).
                Open

                func (i *inventoryManagerImpl) Start(ctx context.Context) error {
                    g, ctx := errgroup.WithContext(ctx)
                    for _, rebalanceManager := range i.rebalanceManagers {
                        rebalanceManager := rebalanceManager
                        g.Go(func() error {
                Severity: Major
                Found in services/rfq/relayer/inventory/manager.go - About 50 mins to fix

                  Method inventoryManagerImpl.initializeTokens has 6 return statements (exceeds 4 allowed).
                  Open

                  func (i *inventoryManagerImpl) initializeTokens(parentCtx context.Context, cfg relconfig.Config) (err error) {
                      i.mux.Lock()
                      defer i.mux.Unlock()
                  
                      ctx, span := i.handler.Tracer().Start(parentCtx, "initializeTokens", trace.WithAttributes(
                  Severity: Major
                  Found in services/rfq/relayer/inventory/manager.go - About 40 mins to fix

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

                    func NewInventoryManager(ctx context.Context, clientFetcher submitter.ClientFetcher, handler metrics.Handler, cfg relconfig.Config, relayer common.Address, txSubmitter submitter.TransactionSubmitter, db reldb.Service) (Manager, error) {
                        rebalanceMethods, err := cfg.GetAllRebalanceMethods()
                        if err != nil {
                            return nil, fmt.Errorf("could not get rebalance methods: %w", err)
                        }
                    Severity: Major
                    Found in services/rfq/relayer/inventory/manager.go - About 35 mins to fix

                      Method inventoryManagerImpl.tryExecuteRebalance has 5 return statements (exceeds 4 allowed).
                      Open

                      func (i *inventoryManagerImpl) tryExecuteRebalance(ctx context.Context, rebalance *RebalanceData) (err error) {
                          ctx, span := i.handler.Tracer().Start(ctx, "tryExecuteRebalance", trace.WithAttributes(
                              attribute.Int("origin", rebalance.OriginMetadata.ChainID),
                              attribute.Int("dest", rebalance.DestMetadata.ChainID),
                              attribute.String("origin_token", rebalance.OriginMetadata.Addr.Hex()),
                      Severity: Major
                      Found in services/rfq/relayer/inventory/manager.go - About 35 mins to fix

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

                                    if addrErr == nil {
                                        span.AddEvent(fmt.Sprintf("got l2 gateway address: %s", parentAddr.Hex()))
                                        err = i.approve(ctx, tokenAddr, parentAddr, backendClient)
                                        if err != nil {
                                            return fmt.Errorf("could not approve L2GatewayRouter contract: %w", err)
                        Severity: Major
                        Found in services/rfq/relayer/inventory/manager.go and 1 other location - About 2 hrs to fix
                        services/rfq/relayer/inventory/manager.go on lines 340..359

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

                        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

                                    if addrErr == nil {
                                        span.AddEvent(fmt.Sprintf("got l1 gateway address: %s", parentAddr.Hex()))
                                        err = i.approve(ctx, tokenAddr, parentAddr, backendClient)
                                        if err != nil {
                                            return fmt.Errorf("could not approve L1GatewayRouter contract: %w", err)
                        Severity: Major
                        Found in services/rfq/relayer/inventory/manager.go and 1 other location - About 2 hrs to fix
                        services/rfq/relayer/inventory/manager.go on lines 362..381

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

                        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