stellar/js-stellar-base

View on GitHub
src/scval.js

Summary

Maintainability
D
1 day
Test Coverage

Function nativeToScVal has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

export function nativeToScVal(val, opts = {}) {
  switch (typeof val) {
    case 'object':
      if (val === null) {
        return xdr.ScVal.scvVoid();
Severity: Minor
Found in src/scval.js - 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

Function nativeToScVal has 95 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function nativeToScVal(val, opts = {}) {
  switch (typeof val) {
    case 'object':
      if (val === null) {
        return xdr.ScVal.scvVoid();
Severity: Major
Found in src/scval.js - About 3 hrs to fix

    Function scValToNative has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function scValToNative(scv) {
      // we use the verbose xdr.ScValType.<type>.value form here because it's faster
      // than string comparisons and the underlying constants never need to be
      // updated
      switch (scv.switch().value) {
    Severity: Major
    Found in src/scval.js - About 2 hrs to fix

      Function scValToNative has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      export function scValToNative(scv) {
        // we use the verbose xdr.ScValType.<type>.value form here because it's faster
        // than string comparisons and the underlying constants never need to be
        // updated
        switch (scv.switch().value) {
      Severity: Minor
      Found in src/scval.js - 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

      Avoid too many return statements within this function.
      Open

            return xdr.ScVal.scvMap(
              Object.entries(val).map(([k, v]) => {
                // the type can be specified with an entry for the key and the value,
                // e.g. val = { 'hello': 1 } and opts.type = { hello: [ 'symbol',
                // 'u128' ]} or you can use `null` for the default interpretation
      Severity: Major
      Found in src/scval.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

              return new ScInt(val, { type: opts?.type }).toScVal();
        Severity: Major
        Found in src/scval.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return xdr.ScVal.scvVec(val.map((v) => nativeToScVal(v, opts)));
          Severity: Major
          Found in src/scval.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return new XdrLargeInt(optType, val).toScVal();
            Severity: Major
            Found in src/scval.js - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status