TryGhost/Ghost

View on GitHub
ghost/core/core/server/models/member.js

Summary

Maintainability
F
5 days
Test Coverage

File member.js has 396 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const ghostBookshelf = require('./base');
const uuid = require('uuid');
const _ = require('lodash');
const config = require('../../shared/config');
const {gravatar} = require('../lib/image');
Severity: Minor
Found in ghost/core/core/server/models/member.js - About 5 hrs to fix

    Function filterRelations has 71 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        filterRelations() {
            return {
                labels: {
                    tableName: 'labels',
                    type: 'manyToMany',
    Severity: Major
    Found in ghost/core/core/server/models/member.js - About 2 hrs to fix

      Member has 25 functions (exceeds 20 allowed). Consider refactoring.
      Open

      const Member = ghostBookshelf.Model.extend({
          tableName: 'members',
      
          defaults() {
              return {
      Severity: Minor
      Found in ghost/core/core/server/models/member.js - About 2 hrs to fix

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

            filterExpansions() {
                return [{
                    key: 'label',
                    replacement: 'labels.slug'
                }, {
        Severity: Minor
        Found in ghost/core/core/server/models/member.js - About 1 hr to fix

          Function onSaving has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              onSaving: function onSaving(model, attr, options) {
                  let labelsToSave = [];
          
                  if (_.isUndefined(this.get('labels'))) {
                      this.unset('labels');
          Severity: Minor
          Found in ghost/core/core/server/models/member.js - About 1 hr to fix

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

                onSaving: function onSaving(model, attr, options) {
                    let labelsToSave = [];
            
                    if (_.isUndefined(this.get('labels'))) {
                        this.unset('labels');
            Severity: Minor
            Found in ghost/core/core/server/models/member.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 updateTierExpiry has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                async updateTierExpiry(products = [], options = {}) {
                    for (const product of products) {
                        if (product?.id) {
                            const expiry = product.expiry_at ? new Date(product.expiry_at) : null;
                            const queryOptions = _.extend({}, options, {
            Severity: Minor
            Found in ghost/core/core/server/models/member.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

                        _.each(this.get('labels'), function each(item) {
                            item.name = item.name && item.name.trim();
                            for (let i = 0; i < labelsToSave.length; i = i + 1) {
                                if (labelsToSave[i].name && item.name && labelsToSave[i].name.toLocaleLowerCase() === item.name.toLocaleLowerCase()) {
                                    return;
            Severity: Major
            Found in ghost/core/core/server/models/member.js and 1 other location - About 6 hrs to fix
            ghost/core/core/server/models/product.js on lines 64..73

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

            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

                add(data, unfilteredOptions = {}) {
                    if (!unfilteredOptions.transacting) {
                        return ghostBookshelf.transaction((transacting) => {
                            return this.add(data, Object.assign({transacting}, unfilteredOptions));
                        });
            Severity: Major
            Found in ghost/core/core/server/models/member.js and 1 other location - About 5 hrs to fix
            ghost/core/core/server/models/member.js on lines 436..449

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

            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

                edit(data, unfilteredOptions = {}) {
                    if (!unfilteredOptions.transacting) {
                        return ghostBookshelf.transaction((transacting) => {
                            return this.edit(data, Object.assign({transacting}, unfilteredOptions));
                        });
            Severity: Major
            Found in ghost/core/core/server/models/member.js and 1 other location - About 5 hrs to fix
            ghost/core/core/server/models/member.js on lines 421..434

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

            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

                    model.related('labels').once('attaching', function onDetaching(collection, labels) {
                        model.related('labels').once('attached', function onDetached(detachedCollection, response, options) {
                            labels.forEach((label) => {
                                label.emitChange('attached', options);
                                model.emitChange('label.attached', options);
            Severity: Major
            Found in ghost/core/core/server/models/member.js and 1 other location - About 3 hrs to fix
            ghost/core/core/server/models/post.js on lines 559..566

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

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

                destroy(unfilteredOptions = {}) {
                    if (!unfilteredOptions.transacting) {
                        return ghostBookshelf.transaction((transacting) => {
                            return this.destroy(Object.assign({transacting}, unfilteredOptions));
                        });
            Severity: Major
            Found in ghost/core/core/server/models/member.js and 2 other locations - About 2 hrs to fix
            ghost/core/core/server/models/member-stripe-customer.js on lines 49..56
            ghost/core/core/server/models/stripe-product.js on lines 44..51

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

            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

                    model.related('labels').once('detaching', function onDetaching(collection, label) {
                        model.related('labels').once('detached', function onDetached(detachedCollection, response, options) {
                            label.emitChange('detached', options);
                            model.emitChange('label.detached', options);
                        });
            Severity: Major
            Found in ghost/core/core/server/models/member.js and 1 other location - About 2 hrs to fix
            ghost/core/core/server/models/post.js on lines 552..557

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

                permittedAttributes: function permittedAttributes() {
                    let filteredKeys = ghostBookshelf.Model.prototype.permittedAttributes.apply(this, arguments);
            
                    this.relationships.forEach((key) => {
                        filteredKeys.push(key);
            Severity: Major
            Found in ghost/core/core/server/models/member.js and 3 other locations - About 2 hrs to fix
            ghost/core/core/server/models/permission.js on lines 20..28
            ghost/core/core/server/models/post.js on lines 246..254
            ghost/core/core/server/models/product.js on lines 97..105

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

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

                                let existingLabel = labels.find((lab) => {
                                    return label.name.toLowerCase() === lab.get('name').toLowerCase();
                                });
            Severity: Major
            Found in ghost/core/core/server/models/member.js and 2 other locations - About 55 mins to fix
            ghost/core/core/server/models/product.js on lines 81..83
            ghost/members-api/lib/repositories/MemberRepository.js on lines 1562..1564

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

            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

                onDestroying: function onDestroyed(model) {
                    ghostBookshelf.Model.prototype.onDestroying.apply(this, arguments);
            
                    this.handleAttachedModels(model);
                },
            Severity: Minor
            Found in ghost/core/core/server/models/member.js and 1 other location - About 40 mins to fix
            ghost/core/core/server/models/post.js on lines 539..543

            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

            There are no issues that match your filters.

            Category
            Status