stellar/js-stellar-base

View on GitHub

Showing 111 of 111 total issues

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

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

  } else if (opts.signer.sha256Hash) {
    let buffer;
    if (typeof opts.signer.sha256Hash === 'string') {
      buffer = Buffer.from(opts.signer.sha256Hash, 'hex');
    } else {
Severity: Major
Found in src/operations/revoke_sponsorship.js and 1 other location - About 4 hrs to fix
src/operations/revoke_sponsorship.js on lines 275..303

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

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

  } else if (opts.signer.preAuthTx) {
    let buffer;
    if (typeof opts.signer.preAuthTx === 'string') {
      buffer = Buffer.from(opts.signer.preAuthTx, 'hex');
    } else {
Severity: Major
Found in src/operations/revoke_sponsorship.js and 1 other location - About 4 hrs to fix
src/operations/revoke_sponsorship.js on lines 288..303

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

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

Function setOptions has 110 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function setOptions(opts) {
  const attributes = {};

  if (opts.inflationDest) {
    if (!StrKey.isValidEd25519PublicKey(opts.inflationDest)) {
Severity: Major
Found in src/operations/set_options.js - About 4 hrs to fix

    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

      File test.ts has 303 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import * as StellarSdk from 'stellar-base';
      
      const masterKey = StellarSdk.Keypair.master(StellarSdk.Networks.TESTNET); // $ExpectType Keypair
      const sourceKey = StellarSdk.Keypair.random(); // $ExpectType Keypair
      const destKey = StellarSdk.Keypair.random();
      Severity: Minor
      Found in types/test.ts - About 3 hrs to fix

        Function fromXDRObject has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

          static fromXDRObject(operation) {
            const result = {};
            if (operation.sourceAccount()) {
              result.source = encodeMuxedAccountToAddress(operation.sourceAccount());
            }
        Severity: Minor
        Found in src/operation.js - About 3 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 constructor has 79 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          constructor(envelope, networkPassphrase) {
            if (typeof envelope === 'string') {
              const buffer = Buffer.from(envelope, 'base64');
              envelope = xdr.TransactionEnvelope.fromXDR(buffer);
            }
        Severity: Major
        Found in src/transaction.js - About 3 hrs to fix

          Function extractRevokeSponshipDetails has 69 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function extractRevokeSponshipDetails(attrs, result) {
            switch (attrs.switch().name) {
              case 'revokeSponsorshipLedgerEntry': {
                const ledgerKey = attrs.ledgerKey();
                switch (ledgerKey.switch().name) {
          Severity: Major
          Found in src/operation.js - About 2 hrs to fix

            Transaction has 24 functions (exceeds 20 allowed). Consider refactoring.
            Open

            export class Transaction extends TransactionBase {
              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 2 hrs to fix

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

              export function revokeSignerSponsorship(opts = {}) {
                if (!StrKey.isValidEd25519PublicKey(opts.account)) {
                  throw new Error('account is invalid');
                }
                let key;
              Severity: Minor
              Found in src/operations/revoke_sponsorship.js - 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

              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

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

                  static predicateAnd(left, right) {
                    if (!(left instanceof xdr.ClaimPredicate)) {
                      throw new Error('left Predicate should be an xdr.ClaimPredicate');
                    }
                    if (!(right instanceof xdr.ClaimPredicate)) {
                Severity: Major
                Found in src/claimant.js and 1 other location - About 2 hrs to fix
                src/claimant.js on lines 61..70

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

                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

                  static predicateOr(left, right) {
                    if (!(left instanceof xdr.ClaimPredicate)) {
                      throw new Error('left Predicate should be an xdr.ClaimPredicate');
                    }
                    if (!(right instanceof xdr.ClaimPredicate)) {
                Severity: Major
                Found in src/claimant.js and 1 other location - About 2 hrs to fix
                src/claimant.js on lines 44..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 80.

                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

                Function buildInvocationTree has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export function buildInvocationTree(root) {
                  const fn = root.function();
                
                  /** @type {InvocationTree} */
                  const output = {};
                Severity: Major
                Found in src/invocation.js - About 2 hrs to fix

                  Function isValid has 48 lines of code (exceeds 25 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

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

                    export function inflation(opts = {}) {
                      const opAttributes = {};
                      opAttributes.body = xdr.OperationBody.inflation();
                      this.setSourceAccount(opAttributes, opts);
                      return new xdr.Operation(opAttributes);
                    Severity: Major
                    Found in src/operations/inflation.js and 1 other location - About 1 hr to fix
                    src/operations/end_sponsoring_future_reserves.js on lines 15..21

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

                    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

                    export function endSponsoringFutureReserves(opts = {}) {
                      const opAttributes = {};
                      opAttributes.body = xdr.OperationBody.endSponsoringFutureReserves();
                      this.setSourceAccount(opAttributes, opts);
                    
                    
                    Severity: Major
                    Found in src/operations/end_sponsoring_future_reserves.js and 1 other location - About 1 hr to fix
                    src/operations/inflation.js on lines 11..16

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

                    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

                    Function revokeSignerSponsorship has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function revokeSignerSponsorship(opts = {}) {
                      if (!StrKey.isValidEd25519PublicKey(opts.account)) {
                        throw new Error('account is invalid');
                      }
                      let key;
                    Severity: Minor
                    Found in src/operations/revoke_sponsorship.js - About 1 hr to fix

                      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

                      Severity
                      Category
                      Status
                      Source
                      Language