TryGhost/Ghost

View on GitHub
ghost/admin/app/models/post.js

Summary

Maintainability
D
2 days
Test Coverage

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

import Ember from 'ember';
import Model, {attr, belongsTo, hasMany} from '@ember-data/model';
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
import boundOneWay from 'ghost-admin/utils/bound-one-way';
import moment from 'moment-timezone';
Severity: Minor
Found in ghost/admin/app/models/post.js - About 4 hrs to fix

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

    export default Model.extend(Comparable, ValidationEngine, {
        session: service(),
        feature: service(),
        ghostPaths: service(),
        clock: service(),
    Severity: Minor
    Found in ghost/admin/app/models/post.js - About 2 hrs to fix

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

          visibilitySegment: computed('visibility', 'isPublic', 'tiers', function () {
              if (this.isPublic) {
                  return this.settings.defaultContentVisibility === 'paid' ? 'status:-free' : 'status:free,status:-free';
              } else {
                  if (this.visibility === 'members') {
      Severity: Minor
      Found in ghost/admin/app/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 statusCompare has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      function statusCompare(postA, postB) {
          let status1 = postA.get('status');
          let status2 = postB.get('status');
      
          // if any of those is empty
      Severity: Minor
      Found in ghost/admin/app/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 compare has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          compare(postA, postB) {
              let updated1 = postA.get('updatedAtUTC');
              let updated2 = postB.get('updatedAtUTC');
              let idResult,
                  publishedAtResult,
      Severity: Minor
      Found in ghost/admin/app/models/post.js - About 1 hr to fix

        Function compare has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            compare(postA, postB) {
                let updated1 = postA.get('updatedAtUTC');
                let updated2 = postB.get('updatedAtUTC');
                let idResult,
                    publishedAtResult,
        Severity: Minor
        Found in ghost/admin/app/models/post.js - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Avoid too many return statements within this function.
        Open

                    return publishedAtResult * -1;
        Severity: Major
        Found in ghost/admin/app/models/post.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return 1;
          Severity: Major
          Found in ghost/admin/app/models/post.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return compare(status1.valueOf(), status2.valueOf());
            Severity: Major
            Found in ghost/admin/app/models/post.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return statusResult;
              Severity: Major
              Found in ghost/admin/app/models/post.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return this.visibility;
                Severity: Major
                Found in ghost/admin/app/models/post.js - About 30 mins to fix

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

                      _getPublishedAtBlogTZ() {
                          let publishedAtUTC = this.publishedAtUTC;
                          let publishedAtBlogDate = this.publishedAtBlogDate;
                          let publishedAtBlogTime = this.publishedAtBlogTime;
                          let blogTimezone = this.settings.timezone;
                  Severity: Minor
                  Found in ghost/admin/app/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

                      didEmailFail: computed('isPost', 'isSent', 'isPublished', 'email.status', function () {
                          return this.isPost
                              && (this.isSent || this.isPublished)
                              && this.email && this.email.status === 'failed';
                      }),
                  Severity: Major
                  Found in ghost/admin/app/models/post.js and 1 other location - About 1 hr to fix
                  ghost/admin/app/models/post.js on lines 176..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 65.

                  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

                      hasBeenEmailed: computed('isPost', 'isSent', 'isPublished', 'email', function () {
                          return this.isPost
                              && (this.isSent || this.isPublished)
                              && this.email && this.email.status !== 'failed';
                      }),
                  Severity: Major
                  Found in ghost/admin/app/models/post.js and 1 other location - About 1 hr to fix
                  ghost/admin/app/models/post.js on lines 182..186

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

                  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

                      updateTags() {
                          let tags = this.tags;
                          let oldTags = tags.filterBy('id', null);
                  
                          tags.removeObjects(oldTags);
                  Severity: Major
                  Found in ghost/admin/app/models/post.js and 1 other location - About 1 hr to fix
                  ghost/admin/app/models/member.js on lines 38..44

                  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

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

                          return this.hasBeenEmailed
                              && !this.session.user.isContributor
                              && this.settings.membersSignupAccess !== 'none'
                              && this.settings.editorDefaultEmailRecipients !== 'disabled'
                              && this.hasBeenEmailed
                  Severity: Major
                  Found in ghost/admin/app/models/post.js and 1 other location - About 1 hr to fix
                  ghost/admin/app/models/post.js on lines 203..207

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

                  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

                          return this.hasBeenEmailed
                              && !this.session.user.isContributor
                              && this.settings.membersSignupAccess !== 'none'
                              && this.settings.editorDefaultEmailRecipients !== 'disabled'
                              && (this.isSent || this.isPublished)
                  Severity: Major
                  Found in ghost/admin/app/models/post.js and 1 other location - About 1 hr to fix
                  ghost/admin/app/models/post.js on lines 193..197

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

                  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