ripple/ripple-rest

View on GitHub
api/lib/validate.js

Summary

Maintainability
F
4 days
Test Coverage

File validate.js has 500 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';
var _ = require('lodash');
var InvalidRequestError = require('./errors.js').InvalidRequestError;
var validator = require('./schema-validator');
var ripple = require('ripple-lib');
Severity: Minor
Found in api/lib/validate.js - About 1 day to fix

    Function validatePayment has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    function validatePayment(payment) {
      if (!isValidAddress(payment.source_account)) {
        throw error('Invalid parameter: source_account. '
          + 'Must be a valid Ripple address');
      }
    Severity: Minor
    Found in api/lib/validate.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 validatePayment has 81 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function validatePayment(payment) {
      if (!isValidAddress(payment.source_account)) {
        throw error('Invalid parameter: source_account. '
          + 'Must be a valid Ripple address');
      }
    Severity: Major
    Found in api/lib/validate.js - About 3 hrs to fix

      Function validateSettings has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      function validateSettings(settings) {
        if (typeof settings !== 'object') {
          throw error('Invalid parameter: settings');
        }
        if (!/(undefined|string)/.test(typeof settings.domain)) {
      Severity: Minor
      Found in api/lib/validate.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 validateSettings has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function validateSettings(settings) {
        if (typeof settings !== 'object') {
          throw error('Invalid parameter: settings');
        }
        if (!/(undefined|string)/.test(typeof settings.domain)) {
      Severity: Major
      Found in api/lib/validate.js - About 2 hrs to fix

        Function validateOptions has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function validateOptions(options) {
          if (options.max_fee !== undefined) {
            validateNonNegativeStringFloat(options.max_fee, 'max_fee');
          }
          if (options.fixed_fee !== undefined) {
        Severity: Minor
        Found in api/lib/validate.js - About 1 hr to fix

          Function validateOptions has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          function validateOptions(options) {
            if (options.max_fee !== undefined) {
              validateNonNegativeStringFloat(options.max_fee, 'max_fee');
            }
            if (options.fixed_fee !== undefined) {
          Severity: Minor
          Found in api/lib/validate.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 validateTrustline has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function validateTrustline(trustline) {
            if (typeof trustline !== 'object') {
              throw error('Invalid parameter: trustline');
            }
            if (_.isUndefined(trustline.limit)) {
          Severity: Minor
          Found in api/lib/validate.js - About 1 hr to fix

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

            function validateTrustline(trustline) {
              if (typeof trustline !== 'object') {
                throw error('Invalid parameter: trustline');
              }
              if (_.isUndefined(trustline.limit)) {
            Severity: Minor
            Found in api/lib/validate.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 validatePaymentMemos has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            function validatePaymentMemos(memos) {
              if (!Array.isArray(memos)) {
                throw error(
                  'Invalid parameter: memos. Must be an array with memo objects');
              }
            Severity: Minor
            Found in api/lib/validate.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 validateOrder has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            function validateOrder(order) {
              if (!order) {
                throw error('Missing parameter: order. '
                  + 'Submission must have order object in JSON form');
              } else if (!/^buy|sell$/.test(order.type)) {
            Severity: Minor
            Found in api/lib/validate.js - About 35 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 validatePathFind has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            function validatePathFind(pathfind) {
              if (!pathfind.source_account) {
                throw error(
                  'Missing parameter: source_account. Must be a valid Ripple address');
              }
            Severity: Minor
            Found in api/lib/validate.js - About 25 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 validatePaging has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            function validatePaging(options) {
              if (options.marker) {
                if (!options.ledger) {
                  throw error('Invalid or Missing Parameter: ledger');
                  // TODO: throw missing('ledger');
            Severity: Minor
            Found in api/lib/validate.js - About 25 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

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

              if (payment.destination_amount
                  && payment.destination_amount.currency.toUpperCase() === 'XRP'
                  && payment.destination_amount.issuer) {
                throw error(
                  'Invalid parameter: destination_amount. XRP cannot have issuer');
            Severity: Minor
            Found in api/lib/validate.js and 1 other location - About 55 mins to fix
            api/lib/validate.js on lines 283..288

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

            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 (payment.source_amount
                  && payment.source_amount.currency.toUpperCase() === 'XRP'
                  && payment.source_amount.issuer) {
                throw error(
                  'Invalid parameter: source_amount. XRP cannot have issuer');
            Severity: Minor
            Found in api/lib/validate.js and 1 other location - About 55 mins to fix
            api/lib/validate.js on lines 277..282

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

            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 (options.submit !== undefined && !_.isBoolean(options.submit)) {
                throw error('"submit" must be boolean, not: ' + options.submit);
              }
            Severity: Minor
            Found in api/lib/validate.js and 1 other location - About 40 mins to fix
            api/lib/validate.js on lines 535..537

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

            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 (options.validated !== undefined && !_.isBoolean(options.validated)) {
                throw error('"validated" must be boolean, not: ' + options.validated);
              }
            Severity: Minor
            Found in api/lib/validate.js and 1 other location - About 40 mins to fix
            api/lib/validate.js on lines 538..540

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

            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 (orderbook.counter && orderbook.counter.currency === 'XRP'
                  && orderbook.counter.counterparty) {
                throw error('Invalid parameter: counter. XRP cannot have counterparty');
              }
            Severity: Minor
            Found in api/lib/validate.js and 1 other location - About 35 mins to fix
            api/lib/validate.js on lines 182..185

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

            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 (orderbook.base && orderbook.base.currency === 'XRP'
                  && orderbook.base.counterparty) {
                throw error('Invalid parameter: base. XRP cannot have counterparty');
              }
            Severity: Minor
            Found in api/lib/validate.js and 1 other location - About 35 mins to fix
            api/lib/validate.js on lines 178..181

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

            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 (!/(undefined|number)/.test(typeof settings.wallet_size)) {
                if (settings.wallet_size !== '') {
                  throw error('Parameter must be a number: wallet_size');
                }
              }
            Severity: Minor
            Found in api/lib/validate.js and 1 other location - About 30 mins to fix
            api/lib/validate.js on lines 383..387

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

            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 (!/(undefined|number)/.test(typeof settings.transfer_rate)) {
                if (settings.transfer_rate !== '') {
                  throw error('Parameter must be a number: transfer_rate');
                }
              }
            Severity: Minor
            Found in api/lib/validate.js and 1 other location - About 30 mins to fix
            api/lib/validate.js on lines 388..392

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

            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