e-ucm/rage-analytics-backend

View on GitHub
lib/games.js

Summary

Maintainability
D
3 days
Test Coverage

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

module.exports = (function () {
    var Q = require('q');
    var Collection = require('easy-collections');
    var db = require('./db');
    var games = new Collection(db, 'games');
Severity: Major
Found in lib/games.js - About 1 day to fix

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

    module.exports = (function () {
        var Q = require('q');
        var Collection = require('easy-collections');
        var db = require('./db');
        var games = new Collection(db, 'games');
    Severity: Minor
    Found in lib/games.js - About 2 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

    Function createGameTemplates has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        games.kibana.createGameTemplates = function (gameId, esClient) {
    
            var deferred = Q.defer();
    
            kibana.getIndexTemplate('defaultIndex', esClient)
    Severity: Major
    Found in lib/games.js - About 2 hrs to fix

      Function modifyGame has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          games.modifyGame = function (gameId, username, body, add) {
              var validationObj = v.validate(body, gameUpdatedSchema);
              if (validationObj.errors && validationObj.errors.length > 0) {
                  throw {
                      message: 'Game bad format: ' + validationObj.errors[0],
      Severity: Minor
      Found in lib/games.js - About 1 hr to fix

        Function removeGame has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            games.removeGame = function (username, gameId) {
                return games.findById(gameId)
                    .then(function (game) {
                        if (!game) {
                            throw {
        Severity: Minor
        Found in lib/games.js - About 1 hr to fix

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

                              if (body.link) {
                                  if (!update.$set) {
                                      update.$set = {};
                                  }
                                  update.$set.link = body.link;
          Severity: Major
          Found in lib/games.js and 2 other locations - About 1 hr to fix
          lib/classes.js on lines 517..523
          lib/games.js on lines 157..162

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

          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

                              if (body.title) {
                                  if (!update.$set) {
                                      update.$set = {};
                                  }
                                  update.$set.title = body.title;
          Severity: Major
          Found in lib/games.js and 2 other locations - About 1 hr to fix
          lib/classes.js on lines 517..523
          lib/games.js on lines 163..168

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

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

                  if (validationObj.errors && validationObj.errors.length > 0) {
                      throw {
                          message: 'Game bad format: ' + validationObj.errors[0],
                          status: 400
                      };
          Severity: Major
          Found in lib/games.js and 7 other locations - About 55 mins to fix
          lib/activities.js on lines 541..546
          lib/auth-tokens.js on lines 139..144
          lib/auth-tokens.js on lines 174..179
          lib/courses.js on lines 69..74
          lib/courses.js on lines 81..86
          lib/games.js on lines 129..134
          lib/versions.js on lines 59..64

          Duplicated Code

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

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

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

          Tuning

          This issue has a mass of 53.

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

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

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

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

          Refactorings

          Further Reading

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

                  if (validationObj.errors && validationObj.errors.length > 0) {
                      throw {
                          message: 'Game bad format: ' + validationObj.errors[0],
                          status: 400
                      };
          Severity: Major
          Found in lib/games.js and 7 other locations - About 55 mins to fix
          lib/activities.js on lines 541..546
          lib/auth-tokens.js on lines 139..144
          lib/auth-tokens.js on lines 174..179
          lib/courses.js on lines 69..74
          lib/courses.js on lines 81..86
          lib/games.js on lines 118..123
          lib/versions.js on lines 59..64

          Duplicated Code

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

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

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

          Tuning

          This issue has a mass of 53.

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

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

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

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

          Refactorings

          Further Reading

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

                      if (!game.public && game.developers.indexOf(username) === -1) {
                          throw {
                              message: 'Game is not public',
                              status: 401
                          };
          Severity: Major
          Found in lib/games.js and 6 other locations - About 40 mins to fix
          lib/courses.js on lines 96..101
          lib/courses.js on lines 130..135
          lib/games.js on lines 145..150
          lib/games.js on lines 196..201
          lib/groupings.js on lines 128..133
          lib/groupings.js on lines 167..172

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

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

                          if (!game.authors || game.authors.indexOf(username) === -1) {
                              throw {
                                  message: 'You don\'t have permission to remove this game.',
                                  status: 401
                              };
          Severity: Major
          Found in lib/games.js and 6 other locations - About 40 mins to fix
          lib/courses.js on lines 96..101
          lib/courses.js on lines 130..135
          lib/games.js on lines 93..98
          lib/games.js on lines 145..150
          lib/groupings.js on lines 128..133
          lib/groupings.js on lines 167..172

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

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

                              if (!game.authors || game.authors.indexOf(username) === -1) {
                                  throw {
                                      message: 'You don\'t have permission to modify this game.',
                                      status: 401
                                  };
          Severity: Major
          Found in lib/games.js and 6 other locations - About 40 mins to fix
          lib/courses.js on lines 96..101
          lib/courses.js on lines 130..135
          lib/games.js on lines 93..98
          lib/games.js on lines 196..201
          lib/groupings.js on lines 128..133
          lib/groupings.js on lines 167..172

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

          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

                          if (!error && response.hits.hits[0]) {
                              fieldsObj = response.hits.hits[0]._source;
                          }
          Severity: Minor
          Found in lib/games.js and 1 other location - About 40 mins to fix
          routes/kibana.js on lines 365..367

          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