HabitRPG/habitrpg

View on GitHub
website/server/libs/payments/subscriptions.js

Summary

Maintainability
F
5 days
Test Coverage

Function prepareSubscriptionValues has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
Open

async function prepareSubscriptionValues (data) {
  let recipient = data.gift ? data.gift.member : data.user;
  const block = shared.content.subscriptionBlocks[data.gift
    ? data.gift.subscription.key
    : data.sub.key];
Severity: Minor
Found in website/server/libs/payments/subscriptions.js - About 1 day 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 createSubscription has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

async function createSubscription (data) {
  const {
    block,
    months,
    plan,
Severity: Minor
Found in website/server/libs/payments/subscriptions.js - About 6 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

File subscriptions.js has 404 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// TODO these files need to refactored.

import _ from 'lodash';
import moment from 'moment';

Severity: Minor
Found in website/server/libs/payments/subscriptions.js - About 5 hrs to fix

    Function createSubscription has 141 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    async function createSubscription (data) {
      const {
        block,
        months,
        plan,
    Severity: Major
    Found in website/server/libs/payments/subscriptions.js - About 5 hrs to fix

      Function prepareSubscriptionValues has 138 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      async function prepareSubscriptionValues (data) {
        let recipient = data.gift ? data.gift.member : data.user;
        const block = shared.content.subscriptionBlocks[data.gift
          ? data.gift.subscription.key
          : data.sub.key];
      Severity: Major
      Found in website/server/libs/payments/subscriptions.js - About 5 hrs to fix

        Function cancelSubscription has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        async function cancelSubscription (data) {
          let plan;
          let group;
          let cancelType = 'unsubscribe';
          let groupId;
        Severity: Major
        Found in website/server/libs/payments/subscriptions.js - About 2 hrs to fix

          Function cancelSubscription has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

          async function cancelSubscription (data) {
            let plan;
            let group;
            let cancelType = 'unsubscribe';
            let groupId;
          Severity: Minor
          Found in website/server/libs/payments/subscriptions.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

          Consider simplifying this complex logical expression.
          Open

              if (
                item.klass === 'mystery'
                  && shared.content.mystery[item.mystery]
                  && dateMoment.isSameOrAfter(shared.content.mystery[item.mystery].start)
                  && dateMoment.isSameOrBefore(moment(shared.content.mystery[item.mystery].end).endOf('day'))
          Severity: Major
          Found in website/server/libs/payments/subscriptions.js - About 40 mins to fix

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

                  let receiverMsg = shared.i18n.t('giftedSubscriptionFull', {
                    username: data.gift.member.profile.name,
                    sender: byUserName,
                    monthCount: shared.content.subscriptionBlocks[data.gift.subscription.key].months,
                  }, languages[1]);
            Severity: Major
            Found in website/server/libs/payments/subscriptions.js and 1 other location - About 2 hrs to fix
            website/server/libs/payments/subscriptions.js on lines 313..317

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

            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

                  let senderMsg = shared.i18n.t('giftedSubscriptionFull', {
                    username: data.gift.member.profile.name,
                    sender: byUserName,
                    monthCount: shared.content.subscriptionBlocks[data.gift.subscription.key].months,
                  }, languages[0]);
            Severity: Major
            Found in website/server/libs/payments/subscriptions.js and 1 other location - About 2 hrs to fix
            website/server/libs/payments/subscriptions.js on lines 320..324

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

            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

              return {
                block,
                months,
                plan,
                recipient,
            Severity: Major
            Found in website/server/libs/payments/subscriptions.js and 1 other location - About 1 hr to fix
            website/server/libs/payments/subscriptions.js on lines 241..253

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

            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 {
                block,
                months,
                plan,
                recipient,
            Severity: Major
            Found in website/server/libs/payments/subscriptions.js and 1 other location - About 1 hr to fix
            website/server/libs/payments/subscriptions.js on lines 225..237

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

            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 _dateDiff (earlyDate, lateDate) {
              if (!earlyDate || !lateDate || moment(lateDate).isBefore(earlyDate)) return 0;
            
              return moment(lateDate).diff(earlyDate, 'months', true);
            }
            Severity: Minor
            Found in website/server/libs/payments/subscriptions.js and 1 other location - About 50 mins to fix
            website/server/libs/payments/groupPayments.js on lines 23..27

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

            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

                group = await Group.getGroup({
                  user: data.user, groupId: data.groupId, populateLeader: false, groupFields,
                });
            Severity: Minor
            Found in website/server/libs/payments/subscriptions.js and 1 other location - About 35 mins to fix
            website/server/libs/payments/subscriptions.js on lines 122..124

            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

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

                group = await Group.getGroup({
                  user: data.user, groupId: data.groupId, populateLeader: false, groupFields,
                });
            Severity: Minor
            Found in website/server/libs/payments/subscriptions.js and 1 other location - About 35 mins to fix
            website/server/libs/payments/subscriptions.js on lines 418..420

            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

                  } else {
                    txnEmail(data.gift.member, 'gifted-subscription', [
                      { name: 'GIFTER', content: byUserName },
                      { name: 'X_MONTHS_SUBSCRIPTION', content: months },
                    ]);
            Severity: Minor
            Found in website/server/libs/payments/subscriptions.js and 1 other location - About 30 mins to fix
            website/server/libs/payments/gems.js on lines 41..46

            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