TryGhost/Ghost

View on GitHub
ghost/members-api/lib/services/MemberBREADService.js

Summary

Maintainability
F
3 days
Test Coverage

File MemberBREADService.js has 315 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const errors = require('@tryghost/errors');
const logging = require('@tryghost/logging');
const tpl = require('@tryghost/tpl');
const moment = require('moment');

Severity: Minor
Found in ghost/members-api/lib/services/MemberBREADService.js - About 3 hrs to fix

    Function add has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        async add(data, options) {
            if (!this.stripeService.configured && (data.comped || data.stripe_customer_id)) {
                const property = data.comped ? 'comped' : 'stripe_customer_id';
                throw new errors.ValidationError({
                    message: tpl(messages.stripeNotConnected),
    Severity: Minor
    Found in ghost/members-api/lib/services/MemberBREADService.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 add has 59 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        async add(data, options) {
            if (!this.stripeService.configured && (data.comped || data.stripe_customer_id)) {
                const property = data.comped ? 'comped' : 'stripe_customer_id';
                throw new errors.ValidationError({
                    message: tpl(messages.stripeNotConnected),
    Severity: Major
    Found in ghost/members-api/lib/services/MemberBREADService.js - About 2 hrs to fix

      Function attachSubscriptionsToMember has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          attachSubscriptionsToMember(member) {
              if (!member.products || !Array.isArray(member.products)) {
                  return member;
              }
      
      
      Severity: Major
      Found in ghost/members-api/lib/services/MemberBREADService.js - About 2 hrs to fix

        Function attachSubscriptionsToMember has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            attachSubscriptionsToMember(member) {
                if (!member.products || !Array.isArray(member.products)) {
                    return member;
                }
        
        
        Severity: Minor
        Found in ghost/members-api/lib/services/MemberBREADService.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 browse has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async browse(options) {
                const defaultWithRelated = [
                    'labels',
                    'stripeSubscriptions',
                    'stripeSubscriptions.customer',
        Severity: Minor
        Found in ghost/members-api/lib/services/MemberBREADService.js - About 1 hr to fix

          Function read has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async read(data, options = {}) {
                  const defaultWithRelated = [
                      'labels',
                      'stripeSubscriptions',
                      'stripeSubscriptions.customer',
          Severity: Minor
          Found in ghost/members-api/lib/services/MemberBREADService.js - About 1 hr to fix

            Function edit has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                async edit(data, options) {
                    delete data.last_seen_at;
            
                    let model;
            
            
            Severity: Minor
            Found in ghost/members-api/lib/services/MemberBREADService.js - About 1 hr to fix

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

                  async edit(data, options) {
                      delete data.last_seen_at;
              
                      let model;
              
              
              Severity: Minor
              Found in ghost/members-api/lib/services/MemberBREADService.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 browse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  async browse(options) {
                      const defaultWithRelated = [
                          'labels',
                          'stripeSubscriptions',
                          'stripeSubscriptions.customer',
              Severity: Minor
              Found in ghost/members-api/lib/services/MemberBREADService.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 fetchSubscriptionOffers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  async fetchSubscriptionOffers(subscriptions) {
                      const fetchedOffers = new Map();
                      const subscriptionOffers = new Map();
              
                      try {
              Severity: Minor
              Found in ghost/members-api/lib/services/MemberBREADService.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

                      try {
                          const attribution = await this.memberAttributionService.getAttributionFromContext(options?.context);
                          if (attribution) {
                              data.attribution = attribution;
                          }
              Severity: Major
              Found in ghost/members-api/lib/services/MemberBREADService.js and 1 other location - About 2 hrs to fix
              ghost/members-api/lib/services/MemberBREADService.js on lines 327..345

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

              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

                      try {
                          // Update email_disabled based on whether the new email is suppressed
                          if (data.email) {
                              const isSuppressed = (await this.emailSuppressionList.getSuppressionData(data.email))?.suppressed;
                              data.email_disabled = !!isSuppressed;
              Severity: Major
              Found in ghost/members-api/lib/services/MemberBREADService.js and 1 other location - About 2 hrs to fix
              ghost/members-api/lib/services/MemberBREADService.js on lines 265..280

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

              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

                                  price: {
                                      id: '',
                                      price_id: '',
                                      nickname: 'Complimentary',
                                      amount: 0,
              Severity: Major
              Found in ghost/members-api/lib/services/MemberBREADService.js and 1 other location - About 1 hr to fix
              ghost/admin/mirage/config/members.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 61.

              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