TryGhost/Ghost

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

Summary

Maintainability
F
2 wks
Test Coverage

File post.js has 1168 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// # Post Model
const _ = require('lodash');
const uuid = require('uuid');
const moment = require('moment');
const {sequence} = require('@tryghost/promise');
Severity: Major
Found in ghost/core/core/server/models/post.js - About 3 days to fix

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

        onSaving: async function onSaving(model, attrs, options) {
            options = options || {};
    
            const self = this;
            let title;
    Severity: Minor
    Found in ghost/core/core/server/models/post.js - About 2 days 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 onSaving has 318 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        onSaving: async function onSaving(model, attrs, options) {
            options = options || {};
    
            const self = this;
            let title;
    Severity: Major
    Found in ghost/core/core/server/models/post.js - About 1 day to fix

      Function onUpdated has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          onUpdated: function onUpdated(model, options) {
              ghostBookshelf.Model.prototype.onUpdated.apply(this, arguments);
      
              model.statusChanging = model.get('status') !== model.previous('status');
              model.isPublished = model.get('status') === 'published';
      Severity: Minor
      Found in ghost/core/core/server/models/post.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

      `` has 37 functions (exceeds 20 allowed). Consider refactoring.
      Open

      Post = ghostBookshelf.Model.extend({
      
          tableName: 'posts',
      
          actionsCollectCRUD: true,
      Severity: Minor
      Found in ghost/core/core/server/models/post.js - About 4 hrs to fix

        Function countRelations has 68 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            countRelations() {
                return {
                    signups(modelOrCollection) {
                        modelOrCollection.query('columns', 'posts.*', (qb) => {
                            qb.count('members_created_events.id')
        Severity: Major
        Found in ghost/core/core/server/models/post.js - About 2 hrs to fix

          Function formatOnWrite has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              formatOnWrite(attrs) {
                  // Ensure all URLs are stored as transform-ready with __GHOST_URL__ representing config.url
                  const urlTransformMap = {
                      mobiledoc: {
                          method: 'mobiledocToTransformReady',
          Severity: Major
          Found in ghost/core/core/server/models/post.js - About 2 hrs to fix

            Function onUpdated has 51 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                onUpdated: function onUpdated(model, options) {
                    ghostBookshelf.Model.prototype.onUpdated.apply(this, arguments);
            
                    model.statusChanging = model.get('status') !== model.previous('status');
                    model.isPublished = model.get('status') === 'published';
            Severity: Major
            Found in ghost/core/core/server/models/post.js - About 2 hrs to fix

              Function permissible has 49 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  permissible: async function permissible(postModel, action, context, unsafeAttrs, loadedPermissions, hasUserPermission, hasApiKeyPermission) {
                      let isContributor;
                      let isOwner;
                      let isAdmin;
                      let isEditor;
              Severity: Minor
              Found in ghost/core/core/server/models/post.js - About 1 hr to fix

                Function permissible has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    permissible: async function permissible(postModel, action, context, unsafeAttrs, loadedPermissions, hasUserPermission, hasApiKeyPermission) {
                        let isContributor;
                        let isOwner;
                        let isAdmin;
                        let isEditor;
                Severity: Minor
                Found in ghost/core/core/server/models/post.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 bulkDestroy has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    bulkDestroy: async function bulkDestroy(ids, tableName, options) {
                        if (tableName === this.prototype.tableName) {
                            if (labs.isSet('collectionsCard')) {
                                // get count of published posts to be destroyed before they no longer exist to count
                                const deletedPublishedCount = await this.query((qb) => {
                Severity: Minor
                Found in ghost/core/core/server/models/post.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 extraFilters has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    extraFilters: function extraFilters(options) {
                        if (!options.status) {
                            return null;
                        }
                
                
                Severity: Minor
                Found in ghost/core/core/server/models/post.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 filterExpansions has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    filterExpansions: function filterExpansions() {
                        const postsMetaKeys = _.without(ghostBookshelf.model('PostsMeta').prototype.orderAttributes(), 'posts_meta.id', 'posts_meta.post_id');
                
                        const expansions = [{
                            key: 'primary_tag',
                Severity: Minor
                Found in ghost/core/core/server/models/post.js - About 1 hr to fix

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

                      edit: function edit(data, unfilteredOptions) {
                          let options = this.filterOptions(unfilteredOptions, 'edit', {extraAllowedProperties: ['id']});
                  
                          const editPost = () => {
                              options.forUpdate = true;
                  Severity: Minor
                  Found in ghost/core/core/server/models/post.js - About 1 hr to fix

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

                        filterRelations: function filterRelations() {
                            return {
                                tags: {
                                    tableName: 'tags',
                                    type: 'manyToMany',
                    Severity: Minor
                    Found in ghost/core/core/server/models/post.js - About 1 hr to fix

                      Function defaults has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          defaults: function defaults() {
                              let visibility = 'public';
                              let tiers = [];
                              const defaultContentVisibility = settingsCache.get('default_content_visibility');
                              if (defaultContentVisibility) {
                      Severity: Minor
                      Found in ghost/core/core/server/models/post.js - About 1 hr to fix

                        Function permissible has 7 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            permissible: async function permissible(postModel, action, context, unsafeAttrs, loadedPermissions, hasUserPermission, hasApiKeyPermission) {
                        Severity: Major
                        Found in ghost/core/core/server/models/post.js - About 50 mins to fix

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

                              formatOnWrite(attrs) {
                                  // Ensure all URLs are stored as transform-ready with __GHOST_URL__ representing config.url
                                  const urlTransformMap = {
                                      mobiledoc: {
                                          method: 'mobiledocToTransformReady',
                          Severity: Minor
                          Found in ghost/core/core/server/models/post.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.get('lexical') &&
                                      (
                                          this.hasChanged('mobiledoc')
                                          || options.force_rerender
                          Severity: Major
                          Found in ghost/core/core/server/models/post.js - About 40 mins to fix

                            Consider simplifying this complex logical expression.
                            Open

                                    if (
                                        !this.get('mobiledoc') &&
                                        (
                                            this.hasChanged('lexical')
                                            || options.force_rerender
                            Severity: Major
                            Found in ghost/core/core/server/models/post.js - About 40 mins to fix

                              Consider simplifying this complex logical expression.
                              Open

                                      if (options.newsletter
                                          && !this.get('newsletter_id')
                                          && this.hasChanged('status')
                                          && (newStatus === 'published' || newStatus === 'scheduled' || newStatus === 'sent')) {
                                          // Map the passed slug to the id + validate the passed newsletter
                              Severity: Major
                              Found in ghost/core/core/server/models/post.js - About 40 mins to fix

                                Function bulkEdit has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    bulkEdit: async function bulkEdit(ids, tableName, options) {
                                        if (tableName === this.prototype.tableName) {
                                            const result = await ghostBookshelf.Model.bulkEdit.call(this, ids, tableName, options);
                                
                                            if (labs.isSet('collectionsCard')) {
                                Severity: Minor
                                Found in ghost/core/core/server/models/post.js - About 35 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

                                Avoid too many return statements within this function.
                                Open

                                        return sequence(ops);
                                Severity: Major
                                Found in ghost/core/core/server/models/post.js - About 30 mins to fix

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

                                      onDestroyed: async function onDestroyed(model, options) {
                                          ghostBookshelf.Model.prototype.onDestroyed.apply(this, arguments);
                                  
                                          if (labs.isSet('collectionsCard') && model.previous('type') === 'post' && model.previous('status') === 'published') {
                                              // reset all page HTML when a published post is deleted so they can be re-rendered
                                  Severity: Minor
                                  Found in ghost/core/core/server/models/post.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 renderIfNeeded has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      renderIfNeeded: async function renderIfNeeded(model, options = {}) {
                                          // pages can have their html cleared to "queue" a re-render to update dynamic data such
                                          // as collection cards. Detect that and re-render here so the page is always up to date
                                          if (model.get('lexical') !== null && model.get('html') === null) {
                                              const html = await lexicalLib.render(model.get('lexical'));
                                  Severity: Minor
                                  Found in ghost/core/core/server/models/post.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

                                      destroy: function destroy(unfilteredOptions) {
                                          let options = this.filterOptions(unfilteredOptions, 'destroy', {extraAllowedProperties: ['id']});
                                  
                                          const destroyPost = () => {
                                              return ghostBookshelf.Model.destroy.call(this, options);
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 4 hrs to fix
                                  ghost/core/core/server/models/user.js on lines 708..723

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

                                  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

                                          Object.entries(urlTransformMap).forEach(([attrToTransform, transform]) => {
                                              let method = transform;
                                              let transformOptions = {};
                                  
                                              if (typeof transform === 'object') {
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 4 hrs to fix
                                  ghost/core/core/server/models/tag.js on lines 41..53

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

                                  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('tags').once('attaching', function tagsAttaching(collection, tags) {
                                              model.related('tags').once('attached', function tagsAttached(detachedCollection, response, options) {
                                                  tags.forEach((tag) => {
                                                      tag.emitChange('attached', options);
                                                      model.emitChange('tag.attached', options);
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 3 hrs to fix
                                  ghost/core/core/server/models/member.js on lines 337..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 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

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

                                      formatsToJSON: function formatsToJSON(attrs, options) {
                                          const defaultFormats = ['html'];
                                          const formatsToKeep = options.formats || defaultFormats;
                                  
                                          // Iterate over all known formats, and if they are not in the keep list, remove them
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 2 hrs to fix
                                  ghost/core/core/server/models/snippet.js on lines 39..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 94.

                                  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('tags').once('detaching', function detachingTags(collection, tag) {
                                              model.related('tags').once('detached', function detachedTags(detachedCollection, response, options) {
                                                  tag.emitChange('detached', options);
                                                  model.emitChange('tag.detached', options);
                                              });
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 2 hrs to fix
                                  ghost/core/core/server/models/member.js on lines 330..335

                                  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/post.js and 3 other locations - About 2 hrs to fix
                                  ghost/core/core/server/models/member.js on lines 352..360
                                  ghost/core/core/server/models/permission.js on lines 20..28
                                  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 2 locations. Consider refactoring.
                                  Open

                                              clicks(modelOrCollection) {
                                                  modelOrCollection.query('columns', 'posts.*', (qb) => {
                                                      qb.countDistinct('members_click_events.member_id')
                                                          .from('members_click_events')
                                                          .join('redirects', 'members_click_events.redirect_id', 'redirects.id')
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 1 hr to fix
                                  ghost/core/core/server/models/label.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 73.

                                  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

                                      tiers() {
                                          return this.belongsToMany('Product', 'posts_products', 'post_id', 'product_id')
                                              .withPivot('sort_order')
                                              .query('orderBy', 'sort_order', 'ASC')
                                              .query((qb) => {
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 1 hr to fix
                                  ghost/core/core/server/models/product.js on lines 107..116

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

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

                                              negative_feedback(modelOrCollection) {
                                                  modelOrCollection.query('columns', 'posts.*', (qb) => {
                                                      qb.count('*')
                                                          .from('members_feedback')
                                                          .whereRaw('posts.id = members_feedback.post_id AND members_feedback.score = 0')
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 8 other locations - About 1 hr to fix
                                  ghost/core/core/server/models/comment.js on lines 226..233
                                  ghost/core/core/server/models/comment.js on lines 234..241
                                  ghost/core/core/server/models/email-batch.js on lines 24..31
                                  ghost/core/core/server/models/newsletter.js on lines 139..146
                                  ghost/core/core/server/models/newsletter.js on lines 147..154
                                  ghost/core/core/server/models/post.js on lines 1550..1557
                                  ghost/core/core/server/models/post.js on lines 1558..1565
                                  ghost/core/core/server/models/post.js on lines 1611..1618

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

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

                                              positive_feedback(modelOrCollection) {
                                                  modelOrCollection.query('columns', 'posts.*', (qb) => {
                                                      qb.sum('score')
                                                          .from('members_feedback')
                                                          .whereRaw('posts.id = members_feedback.post_id')
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 8 other locations - About 1 hr to fix
                                  ghost/core/core/server/models/comment.js on lines 226..233
                                  ghost/core/core/server/models/comment.js on lines 234..241
                                  ghost/core/core/server/models/email-batch.js on lines 24..31
                                  ghost/core/core/server/models/newsletter.js on lines 139..146
                                  ghost/core/core/server/models/newsletter.js on lines 147..154
                                  ghost/core/core/server/models/post.js on lines 1550..1557
                                  ghost/core/core/server/models/post.js on lines 1558..1565
                                  ghost/core/core/server/models/post.js on lines 1603..1610

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

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

                                              paid_conversions(modelOrCollection) {
                                                  modelOrCollection.query('columns', 'posts.*', (qb) => {
                                                      qb.count('members_subscription_created_events.id')
                                                          .from('members_subscription_created_events')
                                                          .whereRaw('posts.id = members_subscription_created_events.attribution_id')
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 8 other locations - About 1 hr to fix
                                  ghost/core/core/server/models/comment.js on lines 226..233
                                  ghost/core/core/server/models/comment.js on lines 234..241
                                  ghost/core/core/server/models/email-batch.js on lines 24..31
                                  ghost/core/core/server/models/newsletter.js on lines 139..146
                                  ghost/core/core/server/models/newsletter.js on lines 147..154
                                  ghost/core/core/server/models/post.js on lines 1550..1557
                                  ghost/core/core/server/models/post.js on lines 1603..1610
                                  ghost/core/core/server/models/post.js on lines 1611..1618

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

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

                                              signups(modelOrCollection) {
                                                  modelOrCollection.query('columns', 'posts.*', (qb) => {
                                                      qb.count('members_created_events.id')
                                                          .from('members_created_events')
                                                          .whereRaw('posts.id = members_created_events.attribution_id')
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 8 other locations - About 1 hr to fix
                                  ghost/core/core/server/models/comment.js on lines 226..233
                                  ghost/core/core/server/models/comment.js on lines 234..241
                                  ghost/core/core/server/models/email-batch.js on lines 24..31
                                  ghost/core/core/server/models/newsletter.js on lines 139..146
                                  ghost/core/core/server/models/newsletter.js on lines 147..154
                                  ghost/core/core/server/models/post.js on lines 1558..1565
                                  ghost/core/core/server/models/post.js on lines 1603..1610
                                  ghost/core/core/server/models/post.js on lines 1611..1618

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

                                  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 (
                                              !this.get('mobiledoc') &&
                                              (
                                                  this.hasChanged('lexical')
                                                  || options.force_rerender
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 1 hr to fix
                                  ghost/core/core/server/models/post.js on lines 736..752

                                  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

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

                                          if (
                                              !this.get('lexical') &&
                                              (
                                                  this.hasChanged('mobiledoc')
                                                  || options.force_rerender
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 1 hr to fix
                                  ghost/core/core/server/models/post.js on lines 757..775

                                  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

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

                                      relationshipConfig: {
                                          tags: {
                                              editable: true
                                          },
                                          authors: {
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 1 hr to fix
                                  ghost/admin/app/routes/posts.js on lines 12..18

                                  Duplicated Code

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

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

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

                                  Tuning

                                  This issue has a mass of 58.

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

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

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

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

                                  Refactorings

                                  Further Reading

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

                                  const messages = {
                                      isAlreadyPublished: 'Your post is already published, please reload your page.',
                                      valueCannotBeBlank: 'Value in {key} cannot be blank.',
                                      expectedPublishedAtInFuture: 'Date must be at least {cannotScheduleAPostBeforeInMinutes} minutes in the future.',
                                      untitled: '(Untitled)',
                                  Severity: Major
                                  Found in ghost/core/core/server/models/post.js and 1 other location - About 1 hr to fix
                                  ghost/members-api/lib/repositories/MemberRepository.js on lines 12..23

                                  Duplicated Code

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

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

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

                                  Tuning

                                  This issue has a mass of 58.

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

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

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

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

                                  Refactorings

                                  Further Reading

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

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

                                  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