TryGhost/Ghost

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

Summary

Maintainability
F
5 days
Test Coverage

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

    edit: function (data, unfilteredOptions) {
        const options = this.filterOptions(unfilteredOptions, 'edit');
        const self = this;

        if (!Array.isArray(data)) {
Severity: Minor
Found in ghost/core/core/server/models/settings.js - About 4 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 settings.js has 348 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const _ = require('lodash');
const uuid = require('uuid');
const crypto = require('crypto');
const keypair = require('keypair');
const ObjectID = require('bson-objectid').default;
Severity: Minor
Found in ghost/core/core/server/models/settings.js - About 4 hrs to fix

    Function populateDefaults has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        populateDefaults: async function populateDefaults(unfilteredOptions) {
            const options = this.filterOptions(unfilteredOptions, 'populateDefaults');
            const self = this;
    
            if (!options.context) {
    Severity: Minor
    Found in ghost/core/core/server/models/settings.js - About 1 hr to fix

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

          edit: function (data, unfilteredOptions) {
              const options = this.filterOptions(unfilteredOptions, 'edit');
              const self = this;
      
              if (!Array.isArray(data)) {
      Severity: Minor
      Found in ghost/core/core/server/models/settings.js - About 1 hr to fix

        Function stripe_plans has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

                async stripe_plans(model, options) {
                    const plans = JSON.parse(model.get('value'));
                    for (const plan of plans) {
                        // Stripe plans used to be allowed (and defaulted to!) 0 amount plans
                        // this causes issues to people importing from older versions of Ghost
        Severity: Minor
        Found in ghost/core/core/server/models/settings.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 parseDefaultSettings has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function parseDefaultSettings() {
            const defaultSettingsInCategories = require('../data/schema/').defaultSettings;
            const defaultSettingsFlattened = {};
        
            const dynamicDefault = {
        Severity: Minor
        Found in ghost/core/core/server/models/settings.js - About 1 hr to fix

          Function promises has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  const promises = data.map(function (item) {
                      if (item.toJSON) {
                          item = item.toJSON();
                      }
                      if (!(_.isString(item.key) && item.key.length > 0)) {
          Severity: Minor
          Found in ghost/core/core/server/models/settings.js - About 1 hr to fix

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

                populateDefaults: async function populateDefaults(unfilteredOptions) {
                    const options = this.filterOptions(unfilteredOptions, 'populateDefaults');
                    const self = this;
            
                    if (!options.context) {
            Severity: Minor
            Found in ghost/core/core/server/models/settings.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 format has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                format() {
                    const attrs = ghostBookshelf.Model.prototype.format.apply(this, arguments);
                    const settingType = attrs.type;
            
                    if (settingType === 'boolean') {
            Severity: Minor
            Found in ghost/core/core/server/models/settings.js - About 55 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 parse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                parse() {
                    const attrs = ghostBookshelf.Model.prototype.parse.apply(this, arguments);
            
                    // transform "0" to false for boolean type
                    const settingType = attrs.type;
            Severity: Minor
            Found in ghost/core/core/server/models/settings.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

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

                format() {
                    const attrs = ghostBookshelf.Model.prototype.format.apply(this, arguments);
                    const settingType = attrs.type;
            
                    if (settingType === 'boolean') {
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 1 other location - About 1 day to fix
            ghost/core/core/server/models/custom-theme-setting.js on lines 30..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 206.

            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

                    async stripe_publishable_key(model) {
                        const value = model.get('value');
                        if (value === null) {
                            return;
                        }
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 2 other locations - About 2 hrs to fix
            ghost/core/core/server/models/settings.js on lines 424..437
            ghost/core/core/server/models/settings.js on lines 438..451

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

                    async stripe_connect_publishable_key(model) {
                        const value = model.get('value');
                        if (value === null) {
                            return;
                        }
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 2 other locations - About 2 hrs to fix
            ghost/core/core/server/models/settings.js on lines 410..423
            ghost/core/core/server/models/settings.js on lines 424..437

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

                    async stripe_connect_secret_key(model) {
                        const value = model.get('value');
                        if (value === null) {
                            return;
                        }
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 2 other locations - About 2 hrs to fix
            ghost/core/core/server/models/settings.js on lines 410..423
            ghost/core/core/server/models/settings.js on lines 438..451

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

                onUpdated: function onUpdated(model, options) {
                    ghostBookshelf.Model.prototype.onUpdated.apply(this, arguments);
            
                    model.emitChange('edited', options);
                    model.emitChange(model.attributes.key + '.' + 'edited', options);
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 2 other locations - About 2 hrs to fix
            ghost/core/core/server/models/settings.js on lines 108..113
            ghost/core/core/server/models/settings.js on lines 115..120

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

            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

                onDestroyed: function onDestroyed(model, options) {
                    ghostBookshelf.Model.prototype.onDestroyed.apply(this, arguments);
            
                    model.emitChange('deleted', options);
                    model.emitChange(model._previousAttributes.key + '.' + 'deleted', options);
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 2 other locations - About 2 hrs to fix
            ghost/core/core/server/models/settings.js on lines 115..120
            ghost/core/core/server/models/settings.js on lines 122..127

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

            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

                onCreated: function onCreated(model, options) {
                    ghostBookshelf.Model.prototype.onCreated.apply(this, arguments);
            
                    model.emitChange('added', options);
                    model.emitChange(model.attributes.key + '.' + 'added', options);
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 2 other locations - About 2 hrs to fix
            ghost/core/core/server/models/settings.js on lines 108..113
            ghost/core/core/server/models/settings.js on lines 122..127

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

            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

                formatOnWrite(attrs) {
                    if (attrs.value && ['cover_image', 'logo', 'icon', 'portal_button_icon', 'og_image', 'twitter_image', 'pintura_js_url', 'pintura_css_url'].includes(attrs.key)) {
                        attrs.value = urlUtils.toTransformReady(attrs.value);
                    }
            
            
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 1 other location - About 1 hr to fix
            ghost/core/core/server/api/endpoints/utils/serializers/input/utils/url.js on lines 60..66

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

            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

            const getGhostKey = doBlock(() => {
                let UNO_KEYPAIRINO;
                return function getKey(type) {
                    if (!UNO_KEYPAIRINO) {
                        UNO_KEYPAIRINO = keypair({bits: 1024});
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 1 other location - About 1 hr to fix
            ghost/core/core/server/models/settings.js on lines 25..33

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

            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

            const getMembersKey = doBlock(() => {
                let UNO_KEYPAIRINO;
                return function getKey(type) {
                    if (!UNO_KEYPAIRINO) {
                        UNO_KEYPAIRINO = keypair({bits: 1024});
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 1 other location - About 1 hr to fix
            ghost/core/core/server/models/settings.js on lines 35..43

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

            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

                    if (settingType === 'boolean' && (attrs.value === 'false' || attrs.value === 'true')) {
                        attrs.value = JSON.parse(attrs.value);
                    }
            Severity: Major
            Found in ghost/core/core/server/models/settings.js and 1 other location - About 1 hr to fix
            ghost/core/core/server/models/custom-theme-setting.js on lines 18..20

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

            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