TryGhost/Ghost

View on GitHub
ghost/core/core/server/models/relations/authors.js

Summary

Maintainability
F
5 days
Test Coverage

Function extendModel has 272 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports.extendModel = function extendModel(Post, Posts, ghostBookshelf) {
    const proto = Post.prototype;

    const Model = Post.extend({
        _handleOptions: function _handleOptions(fnName) {
Severity: Major
Found in ghost/core/core/server/models/relations/authors.js - About 1 day to fix

    Function extendModel has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports.extendModel = function extendModel(Post, Posts, ghostBookshelf) {
        const proto = Post.prototype;
    
        const Model = Post.extend({
            _handleOptions: function _handleOptions(fnName) {
    Severity: Minor
    Found in ghost/core/core/server/models/relations/authors.js - About 1 day 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 permissible has 85 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            permissible: function permissible(postModelOrId, action, context, unsafeAttrs, loadedPermissions, hasUserPermission, hasApiKeyPermission) {
                const self = this;
                const postModel = postModelOrId;
                let origArgs;
                let isContributor;
    Severity: Major
    Found in ghost/core/core/server/models/relations/authors.js - About 3 hrs to fix

      File authors.js has 283 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      const _ = require('lodash');
      const tpl = require('@tryghost/tpl');
      const errors = require('@tryghost/errors');
      const {sequence} = require('@tryghost/promise');
      
      
      Severity: Minor
      Found in ghost/core/core/server/models/relations/authors.js - About 2 hrs to fix

        Function reassignByAuthor has 60 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                reassignByAuthor: async function reassignByAuthor(unfilteredOptions) {
                    let options = this.filterOptions(unfilteredOptions, 'reassignByAuthor', {extraAllowedProperties: ['id']});
                    let authorId = options.id;
        
                    if (!authorId) {
        Severity: Major
        Found in ghost/core/core/server/models/relations/authors.js - About 2 hrs to fix

          Function reassignPost has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                      const reassignPost = (async () => {
                          let trx = options.transacting;
                          let knex = ghostBookshelf.knex;
          
                          try {
          Severity: Minor
          Found in ghost/core/core/server/models/relations/authors.js - About 1 hr to fix

            Function matchAuthors has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    matchAuthors(model, options) {
                        let ownerUser;
                        const ops = [];
            
                        ops.push(() => {
            Severity: Minor
            Found in ghost/core/core/server/models/relations/authors.js - About 1 hr to fix

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

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

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

                            if (_.isNumber(postModelOrId) || _.isString(postModelOrId)) {
                                // Grab the original args without the first one
                                origArgs = _.toArray(arguments).slice(1);
                
                                // Get the actual post model
                Severity: Major
                Found in ghost/core/core/server/models/relations/authors.js and 1 other location - About 5 hrs to fix
                ghost/core/core/server/models/user.js on lines 790..810

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

                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