enhancv/mongoose-subscriptions

View on GitHub

Showing 20 of 20 total issues

File Customer.js has 272 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const mongoose = require("mongoose");
const Address = require("./Address");
const PaymentMethod = require("./PaymentMethod");
const Subscription = require("./Subscription");
const Transaction = require("./Transaction");
Severity: Minor
Found in src/Schema/Customer.js - About 2 hrs to fix

    Consider simplifying this complex logical expression.
    Open

            if (this.isTrial) {
                this.firstBillingDate =
                    this.firstBillingDate ||
                    addTrial(this.trialDuration, this.trialDurationUnit, this.createdAt);
                this.nextBillingDate = this.nextBillingDate || this.firstBillingDate;
    Severity: Critical
    Found in src/Schema/Subscription.js - About 2 hrs to fix

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

      Customer.method("voidProcessor", function voidProcessor(processor, transactionId) {
          this.setSnapshotOriginal();
      
          return processor
              .voidTransaction(this, transactionId)
      Severity: Major
      Found in src/Schema/Customer.js and 1 other location - About 1 hr to fix
      src/Schema/Customer.js on lines 98..103

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

      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

      Customer.method("cancelProcessor", function cancelProcessor(processor, subscriptionId) {
          this.setSnapshotOriginal();
          return processor
              .cancelSubscription(this, subscriptionId)
              .then(customer => customer.clearSnapshotOriginal().save());
      Severity: Major
      Found in src/Schema/Customer.js and 1 other location - About 1 hr to fix
      src/Schema/Customer.js on lines 113..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 69.

      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 4 locations. Consider refactoring.
      Open

      Subscription.virtual("firstBillingWithFreeDate").get(function numberOfFreeMonths() {
          return this.firstBillingDate
              ? new XDate(this.firstBillingDate, true).addMonths(this.numberOfFreeMonths).toDate()
              : null;
      });
      Severity: Major
      Found in src/Schema/Subscription.js and 3 other locations - About 1 hr to fix
      src/Schema/Subscription.js on lines 88..92
      src/Schema/Subscription.js on lines 100..104
      src/Schema/Subscription.js on lines 106..110

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

      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 4 locations. Consider refactoring.
      Open

      Subscription.virtual("nextBillingWithFreeDate").get(function numberOfFreeMonths() {
          return this.nextBillingDate
              ? new XDate(this.nextBillingDate, true).addMonths(this.numberOfFreeMonths).toDate()
              : null;
      });
      Severity: Major
      Found in src/Schema/Subscription.js and 3 other locations - About 1 hr to fix
      src/Schema/Subscription.js on lines 94..98
      src/Schema/Subscription.js on lines 100..104
      src/Schema/Subscription.js on lines 106..110

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

      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 4 locations. Consider refactoring.
      Open

      Subscription.virtual("paidThroughWithFreeDate").get(function numberOfFreeMonths() {
          return this.paidThroughDate
              ? new XDate(this.paidThroughDate, true).addMonths(this.numberOfFreeMonths).toDate()
              : null;
      });
      Severity: Major
      Found in src/Schema/Subscription.js and 3 other locations - About 1 hr to fix
      src/Schema/Subscription.js on lines 88..92
      src/Schema/Subscription.js on lines 94..98
      src/Schema/Subscription.js on lines 106..110

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

      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 4 locations. Consider refactoring.
      Open

      Subscription.virtual("billingPeriodEndWithFreeDate").get(function numberOfFreeMonths() {
          return this.billingPeriodEndDate
              ? new XDate(this.billingPeriodEndDate, true).addMonths(this.numberOfFreeMonths).toDate()
              : null;
      });
      Severity: Major
      Found in src/Schema/Subscription.js and 3 other locations - About 1 hr to fix
      src/Schema/Subscription.js on lines 88..92
      src/Schema/Subscription.js on lines 94..98
      src/Schema/Subscription.js on lines 100..104

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

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

      Customer.method("addSubscription", function addSubscription(
          plan,
          paymentMethod,
          descriptor,
          activeDate
      Severity: Minor
      Found in src/Schema/Customer.js - About 1 hr to fix

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

        const CreditCard = new mongoose.Schema(
            {
                maskedNumber: String,
                cardType: String,
                cardholderName: String,
        Severity: Major
        Found in src/Schema/Transaction/CreditCard.js and 1 other location - About 1 hr to fix
        src/Schema/PaymentMethod/CreditCard.js on lines 3..14

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

        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 CreditCard = new mongoose.Schema(
            {
                maskedNumber: String,
                cardType: String,
                cardholderName: String,
        Severity: Major
        Found in src/Schema/PaymentMethod/CreditCard.js and 1 other location - About 1 hr to fix
        src/Schema/Transaction/CreditCard.js on lines 3..14

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

        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 addSubscription has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        Customer.method("addSubscription", function addSubscription(
            plan,
            paymentMethod,
            descriptor,
            activeDate
        Severity: Minor
        Found in src/Schema/Customer.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

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

        function isExpired(currentDate) {
            const date = currentDate ? new Date(currentDate) : Date.now();
        
            return Boolean(this.expireAt && date > this.expireAt);
        }
        Severity: Major
        Found in src/Schema/Coupon.js and 1 other location - About 1 hr to fix
        src/Schema/Coupon.js on lines 38..42

        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

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

        function isPending(currentDate) {
            const date = currentDate ? new Date(currentDate) : Date.now();
        
            return Boolean(this.startAt && date < this.startAt);
        }
        Severity: Major
        Found in src/Schema/Coupon.js and 1 other location - About 1 hr to fix
        src/Schema/Coupon.js on lines 32..36

        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 AndroidPayCard = new mongoose.Schema(
            {
                sourceCardLast4: String,
                virtualCardLast4: String,
                sourceCardType: String,
        Severity: Minor
        Found in src/Schema/Transaction/AndroidPayCard.js and 1 other location - About 55 mins to fix
        src/Schema/PaymentMethod/AndroidPayCard.js on lines 3..13

        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

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

        const AndroidPayCard = new mongoose.Schema(
            {
                sourceCardLast4: String,
                virtualCardLast4: String,
                sourceCardType: String,
        Severity: Minor
        Found in src/Schema/PaymentMethod/AndroidPayCard.js and 1 other location - About 55 mins to fix
        src/Schema/Transaction/AndroidPayCard.js on lines 3..13

        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

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

                const couponFind =
                    this.coupon instanceof Coupon
                        ? Promise.resolve(this.coupon)
                        : Coupon.findById(this.coupon);
        Severity: Minor
        Found in src/Schema/Discount/Coupon.js and 1 other location - About 30 mins to fix
        src/Schema/Discount/CouponRestricted.js on lines 51..54

        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

        Avoid too many return statements within this function.
        Open

            return null;
        Severity: Major
        Found in src/Schema/Coupon.js - About 30 mins to fix

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

                  const couponFind =
                      this.coupon instanceof Coupon
                          ? Promise.resolve(this.coupon)
                          : Coupon.findById(this.coupon);
          Severity: Minor
          Found in src/Schema/Discount/CouponRestricted.js and 1 other location - About 30 mins to fix
          src/Schema/Discount/Coupon.js on lines 42..45

          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

          Function initializeLocalDates has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          Subscription.method("initializeDates", function initializeLocalDates() {
              if (this.processor.state === ProcessorItem.LOCAL) {
                  if (this.isTrial) {
                      this.firstBillingDate =
                          this.firstBillingDate ||
          Severity: Minor
          Found in src/Schema/Subscription.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

          Severity
          Category
          Status
          Source
          Language