stellar/js-stellar-base

View on GitHub

Showing 57 of 111 total issues

Function constructor has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

  constructor(envelope, networkPassphrase) {
    if (typeof envelope === 'string') {
      const buffer = Buffer.from(envelope, 'base64');
      envelope = xdr.TransactionEnvelope.fromXDR(buffer);
    }
Severity: Minor
Found in src/transaction.js - 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

Function calculateChecksum has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function calculateChecksum(payload) {
  const crcTable = [
    0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108,
    0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210,
    0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b,
Severity: Minor
Found in src/strkey.js - About 1 hr to fix

    Function isValid has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    function isValid(versionByteName, encoded) {
      if (typeof encoded !== 'string') {
        return false;
      }
    
    
    Severity: Minor
    Found in src/strkey.js - 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

    Function setTrustLineFlags has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function setTrustLineFlags(opts = {}) {
      const attributes = {};
    
      if (typeof opts.flags !== 'object' || Object.keys(opts.flags).length === 0) {
        throw new Error('opts.flags must be a map of boolean flags to modify');
    Severity: Minor
    Found in src/operations/set_trustline_flags.js - About 1 hr to fix

      Function best_r has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function best_r(rawNumber) {
        let number = new BigNumber(rawNumber);
        let a;
        let f;
        const fractions = [
      Severity: Minor
      Found in src/util/continued_fraction.js - About 1 hr to fix

        Function checkFastSigningNode has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function checkFastSigningNode() {
          // NOTE: we use commonjs style require here because es6 imports
          // can only occur at the top level.  thanks, obama.
          let sodium;
          try {
        Severity: Minor
        Found in src/signing.js - About 1 hr to fix

          Function pathPaymentStrictReceive has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function pathPaymentStrictReceive(opts) {
            switch (true) {
              case !opts.sendAsset:
                throw new Error('Must specify a send asset');
              case !this.isValidAmount(opts.sendMax):
          Severity: Minor
          Found in src/operations/path_payment_strict_receive.js - About 1 hr to fix

            Function createCustomContract has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function createCustomContract(opts) {
              const salt = Buffer.from(opts.salt || getSalty());
            
              if (!opts.wasmHash || opts.wasmHash.length !== 32) {
                throw new TypeError(
            Severity: Minor
            Found in src/operations/invoke_host_function.js - About 1 hr to fix

              Function pathPaymentStrictSend has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function pathPaymentStrictSend(opts) {
                switch (true) {
                  case !opts.sendAsset:
                    throw new Error('Must specify a send asset');
                  case !this.isValidAmount(opts.sendAmount):
              Severity: Minor
              Found in src/operations/path_payment_strict_send.js - About 1 hr to fix

                Function getClaimableBalanceId has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  getClaimableBalanceId(opIndex) {
                    // Validate and then extract the operation from the transaction.
                    if (
                      !Number.isInteger(opIndex) ||
                      opIndex < 0 ||
                Severity: Minor
                Found in src/transaction.js - About 1 hr to fix

                  Function decodeCheck has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export function decodeCheck(versionByteName, encoded) {
                    if (typeof encoded !== 'string') {
                      throw new TypeError('encoded argument must be of type String');
                    }
                  
                  
                  Severity: Minor
                  Found in src/strkey.js - About 1 hr to fix

                    Function liquidityPoolDeposit has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function liquidityPoolDeposit(opts = {}) {
                      const { liquidityPoolId, maxAmountA, maxAmountB, minPrice, maxPrice } = opts;
                      const attributes = {};
                    
                      if (!liquidityPoolId) {
                    Severity: Minor
                    Found in src/operations/liquidity_pool_deposit.js - About 1 hr to fix

                      Function allowTrust has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      export function allowTrust(opts) {
                        if (!StrKey.isValidEd25519PublicKey(opts.trustor)) {
                          throw new Error('trustor is invalid');
                        }
                        const attributes = {};
                      Severity: Minor
                      Found in src/operations/allow_trust.js - About 1 hr to fix

                        Function constructor has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                          constructor(keys) {
                            if (keys.type !== 'ed25519') {
                              throw new Error('Invalid keys type');
                            }
                        
                        
                        Severity: Minor
                        Found in src/keypair.js - 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

                        Function best_r has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                        export function best_r(rawNumber) {
                          let number = new BigNumber(rawNumber);
                          let a;
                          let f;
                          const fractions = [
                        Severity: Minor
                        Found in src/util/continued_fraction.js - 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

                        Function decodeAddress has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          static decodeAddress(address) {
                            const signerKeyMap = {
                              ed25519PublicKey: xdr.SignerKey.signerKeyTypeEd25519,
                              preAuthTx: xdr.SignerKey.signerKeyTypePreAuthTx,
                              sha256Hash: xdr.SignerKey.signerKeyTypeHashX,
                        Severity: Minor
                        Found in src/signerkey.js - About 1 hr to fix

                          Function toEnvelope has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            toEnvelope() {
                              const rawTx = this.tx.toXDR();
                              const signatures = this.signatures.slice(); // make a copy of the signatures
                          
                              let envelope;
                          Severity: Minor
                          Found in src/transaction.js - About 1 hr to fix

                            Consider simplifying this complex logical expression.
                            Open

                                if (
                                  // == 0
                                  (!allowZero && amount.isZero()) ||
                                  // < 0
                                  amount.isNegative() ||
                            Severity: Major
                            Found in src/operation.js - About 1 hr to fix

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

                                static _validateHashValue(value) {
                                  const error = new Error(
                                    `Expects a 32 byte hash value or hex encoded string. Got ${value}`
                                  );
                              
                              
                              Severity: Minor
                              Found in src/memo.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

                              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

                              Severity
                              Category
                              Status
                              Source
                              Language