getlackey/lackey-cms

View on GitHub
modules/core/server/models/template/index.js

Summary

Maintainability
F
5 days
Test Coverage

Function exports has 271 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    .then((Taggable, TaxonomyType) => {

        SCli.debug(__MODULE_NAME, 'READY');

        /**
Severity: Major
Found in modules/core/server/models/template/index.js - About 1 day to fix

    File index.js has 288 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /* jslint esnext:true, node:true */
    /* globals LACKEY_PATH */
    'use strict';
    
    /*
    Severity: Minor
    Found in modules/core/server/models/template/index.js - About 2 hrs to fix

      Function _preSave has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                  _preSave() {
      
                      return super
                          ._preSave()
                          .then(self => {
      Severity: Major
      Found in modules/core/server/models/template/index.js - About 2 hrs to fix

        Function _populate has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                    _populate() {
        
                        let self = this;
        
                        return super
        Severity: Minor
        Found in modules/core/server/models/template/index.js - About 1 hr to fix

          Function exports has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              .then((Taggable, TaxonomyType) => {
          
                  SCli.debug(__MODULE_NAME, 'READY');
          
                  /**
          Severity: Minor
          Found in modules/core/server/models/template/index.js - About 45 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

          Consider simplifying this complex logical expression.
          Open

                          if (this._doc.type !== 'block' && this._doc.type !== 'variant') {
                              props.og_title = props.og_title || {
                                  label: 'Title (used in OpenGraph)',
                                  name: 'og_title'
                              };
          Severity: Major
          Found in modules/core/server/models/template/index.js - About 40 mins to fix

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

                                        if (self._doc.require) {
                                            if (!Array.isArray(self._doc.require)) {
                                                self._doc.require = [self._doc.require];
                                            }
                                            self._doc.require = JSON.stringify(self._doc.require);
            Severity: Major
            Found in modules/core/server/models/template/index.js and 5 other locations - About 3 hrs to fix
            modules/core/server/models/template/index.js on lines 254..259
            modules/core/server/models/template/index.js on lines 260..265
            modules/core/server/models/template/index.js on lines 266..271
            modules/core/server/models/template/index.js on lines 272..277
            modules/core/server/models/template/index.js on lines 278..283

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

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

                                        if (self._doc.stylesheets) {
                                            if (!Array.isArray(self._doc.stylesheets)) {
                                                self._doc.stylesheets = [self._doc.stylesheets];
                                            }
                                            self._doc.stylesheets = JSON.stringify(self._doc.stylesheets);
            Severity: Major
            Found in modules/core/server/models/template/index.js and 5 other locations - About 3 hrs to fix
            modules/core/server/models/template/index.js on lines 254..259
            modules/core/server/models/template/index.js on lines 266..271
            modules/core/server/models/template/index.js on lines 272..277
            modules/core/server/models/template/index.js on lines 278..283
            modules/core/server/models/template/index.js on lines 284..289

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

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

                                        if (self._doc.javascripts) {
                                            if (!Array.isArray(self._doc.javascripts)) {
                                                self._doc.javascripts = [self._doc.javascripts];
                                            }
                                            self._doc.javascripts = JSON.stringify(self._doc.javascripts);
            Severity: Major
            Found in modules/core/server/models/template/index.js and 5 other locations - About 3 hrs to fix
            modules/core/server/models/template/index.js on lines 260..265
            modules/core/server/models/template/index.js on lines 266..271
            modules/core/server/models/template/index.js on lines 272..277
            modules/core/server/models/template/index.js on lines 278..283
            modules/core/server/models/template/index.js on lines 284..289

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

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

                                        if (self._doc.expose) {
                                            if (!Array.isArray(self._doc.expose)) {
                                                self._doc.expose = [self._doc.expose];
                                            }
                                            self._doc.expose = JSON.stringify(self._doc.expose);
            Severity: Major
            Found in modules/core/server/models/template/index.js and 5 other locations - About 3 hrs to fix
            modules/core/server/models/template/index.js on lines 254..259
            modules/core/server/models/template/index.js on lines 260..265
            modules/core/server/models/template/index.js on lines 266..271
            modules/core/server/models/template/index.js on lines 278..283
            modules/core/server/models/template/index.js on lines 284..289

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

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

                                        if (self._doc.populate) {
                                            if (!Array.isArray(self._doc.populate)) {
                                                self._doc.populate = [self._doc.populate];
                                            }
                                            self._doc.populate = JSON.stringify(self._doc.populate);
            Severity: Major
            Found in modules/core/server/models/template/index.js and 5 other locations - About 3 hrs to fix
            modules/core/server/models/template/index.js on lines 254..259
            modules/core/server/models/template/index.js on lines 260..265
            modules/core/server/models/template/index.js on lines 272..277
            modules/core/server/models/template/index.js on lines 278..283
            modules/core/server/models/template/index.js on lines 284..289

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

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

                                        if (self._doc.variants) {
                                            if (!Array.isArray(self._doc.variants)) {
                                                self._doc.variants = [self._doc.variants];
                                            }
                                            self._doc.variants = JSON.stringify(self._doc.variants);
            Severity: Major
            Found in modules/core/server/models/template/index.js and 5 other locations - About 3 hrs to fix
            modules/core/server/models/template/index.js on lines 254..259
            modules/core/server/models/template/index.js on lines 260..265
            modules/core/server/models/template/index.js on lines 266..271
            modules/core/server/models/template/index.js on lines 272..277
            modules/core/server/models/template/index.js on lines 284..289

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

            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

                            return SCli
                                .sql(this.model
                                    .query()
                                    .where('selectable', true)
                                    .where('type', 'template')
            Severity: Major
            Found in modules/core/server/models/template/index.js and 1 other location - About 1 hr to fix
            modules/core/server/models/template/index.js on lines 163..180

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

            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

            module.exports = SUtils
                .waitForAs(__MODULE_NAME,
                    SUtils.cmsMod('core').model('taggable'),
                    SUtils.cmsMod('core').model('taxonomy-type'),
                    require('../knex')
            Severity: Minor
            Found in modules/core/server/models/template/index.js and 1 other location - About 55 mins to fix
            modules/core/server/models/activity-log/index.js on lines 29..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 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

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

                                    if (typeof self._doc.stylesheets === 'string') {
                                        self._doc.stylesheets = JSON.parse(self._doc.stylesheets);
                                    }
            Severity: Major
            Found in modules/core/server/models/template/index.js and 4 other locations - About 50 mins to fix
            modules/core/server/models/role/index.js on lines 195..197
            modules/core/server/models/template/index.js on lines 336..338
            modules/core/server/models/template/index.js on lines 342..344
            modules/core/server/models/template/index.js on lines 345..347

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 52.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

                                    if (typeof self._doc.javascripts === 'string') {
                                        self._doc.javascripts = JSON.parse(self._doc.javascripts);
                                    }
            Severity: Major
            Found in modules/core/server/models/template/index.js and 4 other locations - About 50 mins to fix
            modules/core/server/models/role/index.js on lines 195..197
            modules/core/server/models/template/index.js on lines 339..341
            modules/core/server/models/template/index.js on lines 342..344
            modules/core/server/models/template/index.js on lines 345..347

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 52.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

                                    if (typeof self._doc.expose === 'string') {
                                        self._doc.expose = JSON.parse(self._doc.expose);
                                    }
            Severity: Major
            Found in modules/core/server/models/template/index.js and 4 other locations - About 50 mins to fix
            modules/core/server/models/role/index.js on lines 195..197
            modules/core/server/models/template/index.js on lines 336..338
            modules/core/server/models/template/index.js on lines 339..341
            modules/core/server/models/template/index.js on lines 345..347

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 52.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

                                    if (typeof self._doc.require === 'string') {
                                        self._doc.require = JSON.parse(self._doc.require);
                                    }
            Severity: Major
            Found in modules/core/server/models/template/index.js and 4 other locations - About 50 mins to fix
            modules/core/server/models/role/index.js on lines 195..197
            modules/core/server/models/template/index.js on lines 336..338
            modules/core/server/models/template/index.js on lines 339..341
            modules/core/server/models/template/index.js on lines 342..344

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 52.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status