makeomatic/ms-payments

View on GitHub

Showing 93 of 93 total issues

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

function planList({ params: opts }) {
  const { redis } = this;
  const { filter, criteria } = opts;
  const strFilter = typeof filter === 'string' ? filter : fsort.filter(filter || {});
  const order = opts.order || 'ASC';
Severity: Major
Found in src/actions/plan/list.js and 1 other location - About 7 hrs to fix
src/actions/sale/list.js on lines 20..32

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

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

function saleList({ params: opts }) {
  const { redis } = this;
  const { filter, criteria } = opts;
  const strFilter = typeof filter === 'string' ? filter : fsort.filter(filter || {});
  const order = opts.order || 'ASC';
Severity: Major
Found in src/actions/sale/list.js and 1 other location - About 7 hrs to fix
src/actions/plan/list.js on lines 20..32

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

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

  function sendRequest() {
    return createPayment(sale, config.paypal).then((newSale) => {
      const approval = find(newSale.links, { rel: 'approval_url' });
      if (approval === null) {
        throw new NotSupportedError('Unexpected PayPal response!');
Severity: Major
Found in src/actions/sale/createDynamic.js and 1 other location - About 4 hrs to fix
src/actions/sale/create.js on lines 81..95

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

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

  function sendRequest(request) {
    return createPayment(request, config.paypal).then((newSale) => {
      const approval = find(newSale.links, { rel: 'approval_url' });
      if (approval === null) {
        throw new NotSupportedError('Unexpected PayPal response!');
Severity: Major
Found in src/actions/sale/create.js and 1 other location - About 4 hrs to fix
src/actions/sale/createDynamic.js on lines 56..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 123.

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 createSaveToRedis has 66 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function createSaveToRedis(redis, message) {
  return function saveToRedis(data) {
    const { plan, plans } = data;
    const { meta, level, title } = message;
    const aliasedId = message.alias || plan.id;
Severity: Major
Found in src/actions/plan/create.js - About 2 hrs to fix

    Function saveToRedis has 64 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      return function saveToRedis(data) {
        const { plan, plans } = data;
        const { meta, level, title } = message;
        const aliasedId = message.alias || plan.id;
        const hidden = message.hidden || false;
    Severity: Major
    Found in src/actions/plan/create.js - About 2 hrs to fix

      Function updateRedis has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function updateRedis(sale) {
        const { redis } = this;
        const { state } = sale;
      
        if (state !== 'approved') {
      Severity: Minor
      Found in src/actions/sale/execute.js - About 1 hr to fix

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

        function processKeys(amqp) {
          const { config, log, redis } = this;
          const { keyPrefix } = config.redis.options;
          const masterNode = getRedisMasterNode(redis, config);
          const pipeline = redis.pipeline();
        Severity: Minor
        Found in src/migrations/generate-users-ids/index.js - About 1 hr to fix

          Function cleanupCache has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function cleanupCache(_index) {
            const { redis, redisType, config } = this;
            const { keyPrefix } = config.redis.options;
            const keyPrefixLength = keyPrefix.length;
            const index = `${keyPrefix}${_index}`;
          Severity: Minor
          Found in src/list-utils.js - About 1 hr to fix

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

            async function agreementExecute({ params }) {
              const { config, redis, amqp } = this;
              const { token } = params;
            
              let agreementData;
            Severity: Minor
            Found in src/actions/agreement/execute.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 getUsers has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            async function getUsers(ctx, opts = {}) {
              const { audience, amqp, usersList, pulledUsers, pool } = ctx;
            
              // give 5 minutes based on due date
              const current = opts.start || moment().subtract(5, 'minutes').valueOf();
            Severity: Minor
            Found in src/actions/agreement/sync.js - About 1 hr to fix

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

              function sendRequest(config, message) {
                const defaultMerchantPreferences = {
                  return_url: config.urls.plan_return,
                  cancel_url: config.urls.plan_cancel,
                  auto_bill_amount: 'YES',
              Severity: Minor
              Found in src/actions/plan/create.js - About 1 hr to fix

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

                const publishHook = (amqp, event, payload) => amqp.publish(
                  'payments.hook.publish',
                  { event, payload },
                  {
                    confirm: true,
                Severity: Major
                Found in src/actions/agreement/state.js and 1 other location - About 1 hr to fix
                src/utils/paypal/billing-hooks.js on lines 8..17

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

                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

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

                const publishHook = (amqp, event, payload) => amqp.publish(
                  'payments.hook.publish',
                  { event, payload },
                  {
                    confirm: true,
                Severity: Major
                Found in src/utils/paypal/billing-hooks.js and 1 other location - About 1 hr to fix
                src/actions/agreement/state.js on lines 32..41

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

                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 saveAgreement has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                async function saveAgreement(redis, token, agreement, owner, planId, creatorTaskId, finalizedAt) {
                Severity: Major
                Found in src/actions/agreement/execute.js - About 50 mins to fix

                  Function fetchUpdatedAgreement has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  async function fetchUpdatedAgreement(paypalCfg, log, agreementId, owner, token, creatorTaskId) {
                  Severity: Minor
                  Found in src/actions/agreement/execute.js - About 45 mins to fix

                    Function agreementBill has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                    async function agreementBill({ log, params }) {
                      const { agreement: id, username: owner, subscriptionInterval } = params;
                      const { amqp } = this;
                    
                      log.debug('billing %s on %s', owner, id);
                    Severity: Minor
                    Found in src/actions/agreement/bill.js - About 45 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

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

                      function updateCommon(data) {
                        return Promise.bind(this, parseSale(data.sale, message.owner)).then(saveCommon).return(data);
                      }
                    Severity: Minor
                    Found in src/actions/sale/createDynamic.js and 1 other location - About 45 mins to fix
                    src/actions/sale/create.js on lines 117..119

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

                    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

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

                      function updateCommon(data) {
                        return Promise.bind(this, parseSale(data.sale, message.owner)).then(saveCommon).return(data);
                      }
                    Severity: Minor
                    Found in src/actions/sale/create.js and 1 other location - About 45 mins to fix
                    src/actions/sale/createDynamic.js on lines 93..95

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

                    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 calculateDiscounts has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    function calculateDiscounts(subscription, customSetupFee, skipSetupFee, trialDiscount, trialCycle) {
                    Severity: Minor
                    Found in src/actions/agreement/create.js - About 35 mins to fix
                      Severity
                      Category
                      Status
                      Source
                      Language