synapsecns/sanguine

View on GitHub
packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts

Summary

Maintainability
C
1 day
Test Coverage

Function getSwapToTokens has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

export const getSwapToTokens = ({
  fromChainId,
  fromTokenRouteSymbol,
  toChainId,
  toTokenRouteSymbol,
Severity: Minor
Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - 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

Avoid too many return statements within this function.
Open

    return _(EXISTING_SWAP_ROUTES)
      .pickBy((_values, key) => key.startsWith(`${fromTokenRouteSymbol}-`))
      .values()
      .flatten()
      .uniq()
Severity: Major
Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

        return _(EXISTING_SWAP_ROUTES)
          .mapValues((values) =>
            values.filter((token) => token === `${toTokenRouteSymbol}-${toChainId}`)
          )
          .values()
    Severity: Major
    Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

          return _(EXISTING_SWAP_ROUTES)
            .mapValues((values) =>
              values.filter((token) => token === `${toTokenRouteSymbol}-${toChainId}`)
            )
            .pickBy((_values, key) => key.startsWith(`${fromTokenRouteSymbol}-`))
      Severity: Major
      Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return _(EXISTING_SWAP_ROUTES).values().flatten().uniq().value()
        Severity: Major
        Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return EXISTING_SWAP_ROUTES[
                `${fromTokenRouteSymbol}-${fromChainId}`
              ]?.filter((value) => value.endsWith(`-${toChainId}`))
          Severity: Major
          Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return _(EXISTING_SWAP_ROUTES)
                  .pickBy((_values, key) => key.endsWith(`-${fromChainId}`))
                  .values()
                  .flatten()
                  .filter((value) => value.endsWith(`-${toChainId}`))
            Severity: Major
            Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return _(EXISTING_SWAP_ROUTES)
                    .pickBy((_values, key) => key.endsWith(`-${fromChainId}`))
                    .values()
                    .flatten()
                    .uniq()
              Severity: Major
              Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return EXISTING_SWAP_ROUTES[
                      `${fromTokenRouteSymbol}-${fromChainId}`
                    ]?.filter((token) => token.endsWith(`-${toChainId}`))
                Severity: Major
                Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return EXISTING_SWAP_ROUTES[`${fromTokenRouteSymbol}-${fromChainId}`]
                  Severity: Major
                  Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return _(EXISTING_SWAP_ROUTES)
                          .values()
                          .flatten()
                          .filter((token) => token.endsWith(`-${toChainId}`))
                          .uniq()
                    Severity: Major
                    Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                          return _(EXISTING_SWAP_ROUTES)
                            .mapValues((values) =>
                              values.filter((token) => token === `${toTokenRouteSymbol}-${toChainId}`)
                            )
                            .pickBy((_values, key) => key.endsWith(`-${fromChainId}`))
                      Severity: Major
                      Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return _(EXISTING_SWAP_ROUTES)
                              .pickBy((_values, key) => key.startsWith(`${fromTokenRouteSymbol}-`))
                              .values()
                              .flatten()
                              .filter((token) => token.endsWith(`-${toChainId}`))
                        Severity: Major
                        Found in packages/synapse-interface/utils/swapFinder/getSwapToTokens.ts - About 30 mins to fix

                          There are no issues that match your filters.

                          Category
                          Status