appirio-tech/lc1-discussion-service

View on GitHub
lib/controllerHelper.js

Summary

Maintainability
F
4 days
Test Coverage

File controllerHelper.js has 340 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * Copyright (c) 2014 TopCoder, Inc. All rights reserved.
 */
/**
 * Helper methods for controller logic.
Severity: Minor
Found in lib/controllerHelper.js - About 4 hrs to fix

    Function _buildReferenceFilter has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function _buildReferenceFilter(referenceModels, req, callback) {
      var filters = { where: {} };   // start with emtpty filter
      if (!referenceModels) {
        callback(null, filters);
      } else {
    Severity: Minor
    Found in lib/controllerHelper.js - About 1 hr to fix

      Function updateEntity has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function updateEntity(model, referenceModels, options, req, funcCallback) {
        async.waterfall([
          function(callback) {
            _checkExtraParameters(req, callback);
          },
      Severity: Minor
      Found in lib/controllerHelper.js - About 1 hr to fix

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

        function deleteEntity(model, referenceModels, options, req, funcCallback) {
          async.waterfall([
            function(callback) {
              _checkExtraParameters(req, callback);
            },
        Severity: Minor
        Found in lib/controllerHelper.js - About 1 hr to fix

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

          function createEntity(model, referenceModels, options, req, funcCallback) {
            async.waterfall([
              function(callback) {
                _checkExtraParameters(req, callback);
              },
          Severity: Minor
          Found in lib/controllerHelper.js - About 1 hr to fix

            Function update has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function update(model, referenceModels, options, req, res, next) {
            Severity: Minor
            Found in lib/controllerHelper.js - About 45 mins to fix

              Function get has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              function get(model, referenceModels, options, req, res, next) {
              Severity: Minor
              Found in lib/controllerHelper.js - About 45 mins to fix

                Function create has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                function create(model, referenceModels, options, req, res, next) {
                Severity: Minor
                Found in lib/controllerHelper.js - About 45 mins to fix

                  Function all has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  function all(model, referenceModels, options, req, res, next) {
                  Severity: Minor
                  Found in lib/controllerHelper.js - About 45 mins to fix

                    Function deleteMethod has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    function deleteMethod(model, referenceModels, options, req, res, next) {
                    Severity: Minor
                    Found in lib/controllerHelper.js - About 45 mins to fix

                      Function deleteEntity has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      function deleteEntity(model, referenceModels, options, req, funcCallback) {
                      Severity: Minor
                      Found in lib/controllerHelper.js - About 35 mins to fix

                        Function _buildQueryFilter has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        function _buildQueryFilter(model, filtering, filters, req, callback) {
                        Severity: Minor
                        Found in lib/controllerHelper.js - About 35 mins to fix

                          Function updateEntity has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          function updateEntity(model, referenceModels, options, req, funcCallback) {
                          Severity: Minor
                          Found in lib/controllerHelper.js - About 35 mins to fix

                            Function allEntities has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            function allEntities(model, referenceModels, options, req, funcCallback) {
                            Severity: Minor
                            Found in lib/controllerHelper.js - About 35 mins to fix

                              Function createEntity has 5 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                              function createEntity(model, referenceModels, options, req, funcCallback) {
                              Severity: Minor
                              Found in lib/controllerHelper.js - About 35 mins to fix

                                Function getEntity has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                function getEntity(model, referenceModels, options, req, funcCallback) {
                                Severity: Minor
                                Found in lib/controllerHelper.js - About 35 mins to fix

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

                                  function update(model, referenceModels, options, req, res, next) {
                                    updateEntity(model, referenceModels, options, req, function(err, entity) {
                                      if (!err) {
                                        req.data = {
                                          id: entity.id,
                                  Severity: Major
                                  Found in lib/controllerHelper.js and 1 other location - About 2 hrs to fix
                                  lib/controllerHelper.js on lines 330..343

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

                                  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

                                  function create(model, referenceModels, options, req, res, next) {
                                    createEntity(model, referenceModels, options, req, function(err, entity) {
                                      if (!err) {
                                        req.data = {
                                          id: entity.id,
                                  Severity: Major
                                  Found in lib/controllerHelper.js and 1 other location - About 2 hrs to fix
                                  lib/controllerHelper.js on lines 401..414

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

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

                                      function(filters, callback) {
                                        // use entity filter IDs if configured
                                        if (options && options.entityFilterIDs) {
                                          filters.where = _.omit(filters.where, function(value, key) {
                                            return options.entityFilterIDs.indexOf(key) === -1;
                                  Severity: Major
                                  Found in lib/controllerHelper.js and 3 other locations - About 2 hrs to fix
                                  lib/controllerHelper.js on lines 245..253
                                  lib/controllerHelper.js on lines 361..369
                                  lib/controllerHelper.js on lines 432..440

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

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

                                      function(filters, callback) {
                                        // use entity filter IDs if configured
                                        if (options && options.entityFilterIDs) {
                                          filters.where = _.omit(filters.where, function(value, key) {
                                            return options.entityFilterIDs.indexOf(key) === -1;
                                  Severity: Major
                                  Found in lib/controllerHelper.js and 3 other locations - About 2 hrs to fix
                                  lib/controllerHelper.js on lines 189..198
                                  lib/controllerHelper.js on lines 245..253
                                  lib/controllerHelper.js on lines 361..369

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

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

                                      function(filters, callback) {
                                        // use entity filter IDs if configured
                                        if (options && options.entityFilterIDs) {
                                          filters.where = _.omit(filters.where, function(value, key) {
                                            return options.entityFilterIDs.indexOf(key) === -1;
                                  Severity: Major
                                  Found in lib/controllerHelper.js and 3 other locations - About 2 hrs to fix
                                  lib/controllerHelper.js on lines 189..198
                                  lib/controllerHelper.js on lines 361..369
                                  lib/controllerHelper.js on lines 432..440

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

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

                                      function(filters, callback) {
                                        // use entity filter IDs if configured
                                        if (options && options.entityFilterIDs) {
                                          filters.where = _.omit(filters.where, function(value, key) {
                                            return options.entityFilterIDs.indexOf(key) === -1;
                                  Severity: Major
                                  Found in lib/controllerHelper.js and 3 other locations - About 2 hrs to fix
                                  lib/controllerHelper.js on lines 189..198
                                  lib/controllerHelper.js on lines 245..253
                                  lib/controllerHelper.js on lines 432..440

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

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

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

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

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

                                  Refactorings

                                  Further Reading

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

                                    allEntities(model, referenceModels, options, req, function(err, totalCount, entities) {
                                      if (!err) {
                                        req.data = {
                                          success: true,
                                          status: 200,
                                  Severity: Major
                                  Found in lib/controllerHelper.js and 2 other locations - About 1 hr to fix
                                  api/controllers/messages.js on lines 61..73
                                  api/controllers/messages.js on lines 96..108

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

                                  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

                                        entity.destroy().success(function() {
                                          callback(null, entity);
                                        })
                                        .error(function(err) {
                                          routeHelper.addError(req, err);
                                  Severity: Major
                                  Found in lib/controllerHelper.js and 1 other location - About 1 hr to fix
                                  lib/controllerHelper.js on lines 379..385

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

                                        entity.save().success(function() {
                                          callback(null, entity);
                                        })
                                        .error(function(err) {
                                          routeHelper.addError(req, err);
                                  Severity: Major
                                  Found in lib/controllerHelper.js and 1 other location - About 1 hr to fix
                                  lib/controllerHelper.js on lines 442..448

                                  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

                                  There are no issues that match your filters.

                                  Category
                                  Status